我有一个我想传递给的对象.fadeOut().
在我们开始之前,我可以将对象传递给.click():
this.$title.click({story: this}, function (event){
var story = event.data.story;
}
Run Code Online (Sandbox Code Playgroud)
很简单.
现在我想做类似的事情.fadeOut:
this.$title.fadeOut("fast", {story: this}, function(){
var story = ???
});
Run Code Online (Sandbox Code Playgroud)
哪个不起作用.但你明白了吗?我怎样才能this进入anon函数?
我正在寻找最干净的解决方案.除此之外,我正在寻找最符合我所做的解决方案.click().
谢谢!
ASIDE:有更清洁的方式this进入.click()吗?
在收到来自 API 的响应后,我有以下内容:
JObject goatHerd = JObject.Parse(responseString);
JToken goat = goatHerd["value"];
Run Code Online (Sandbox Code Playgroud)
现在goat将包含一个数据数组,或者它将是一个空数组。如何检查是否为空?
我试过这样的事情:
if(goat != null){}
Run Code Online (Sandbox Code Playgroud)
不幸的是,goat实际上等于{[]}根据 Visual Studio。
我不能这样做:
if(goat.length != 0){}
Run Code Online (Sandbox Code Playgroud)
因为.length不适用于JToken.
谢谢你的帮助。
我正在使用 Storybook 的action()在组件上创建事件侦听器。
这似乎有效:
import { action } from '@storybook/addon-actions';
...
<custom-link-component>
<a
href="https://google.com"
onBlur={action('blur')}
>
Google
</a>
</custom-link-component>
Run Code Online (Sandbox Code Playgroud)
Storybook 在“操作”窗格中记录事件。然而,代码有点奇怪,因为它action()是调用的,而不是传递的,这不是事件通常的工作方式。这可能稍后会有意义。
这不起作用,因为该操作未记录在故事书中:
import { action } from '@storybook/addon-actions';
...
<custom-link-component>
<a
href="https://google.com"
onBlur={(e) => {console.log(e); action('blur');}}
>
Google
</a>
</custom-link-component>
Run Code Online (Sandbox Code Playgroud)
唯一的区别是action()在匿名函数内部调用。console.log()然而,射击正确。
我怀疑我在这里遗漏了一些基本的东西,我只是不确定是什么。为什么action('blur')在第一个示例中调用?为什么action('blur')在第二个示例中似乎不起作用?
两个小提琴的故事(请在jsfiddle页面加载后使用运行按钮以更清楚地了解发生的事情).
死简单:
$("body").addClass("noScroll");
alert($("body").hasClass("noScroll"));
$("body").removeClass("noScroll");
alert($("body").hasClass("noScroll"));
Run Code Online (Sandbox Code Playgroud)
有了这个css:
.noScroll {
background-color: pink;
position: fixed;
width: 100%;
top: 200px;
}
Run Code Online (Sandbox Code Playgroud)
我们上课了.该类被添加到body中,改变了body的外观/行为.该类将从正文中删除,并且正文将恢复为默认值.按预期工作.
$("body").addClass("noScroll");
alert($("body").hasClass("noScroll"));
$(".noScroll").css({
"background-color" : "pink",
"position" : "fixed",
"width" : "100%",
"top" : "200px"
});
$("body").removeClass("noScroll");
alert($("body").hasClass("noScroll"));
Run Code Online (Sandbox Code Playgroud)
这次没有附带的CSS,因为它是由jQuery添加的,但在其他方面非常类似于上面.努力到位.CSS已应用,但未删除.为什么会这样?
谢谢!
Railsscaffold生成了以下内容:
respond_to do |format|
if @student.save
format.html { redirect_to @student, notice => 'Student was successfully created.' }
format.json { render :show, status: :created, location: @student }
else
format.html { render :new }
format.json { render json: @student.errors, status: :unprocessable_entity }
end
end
Run Code Online (Sandbox Code Playgroud)
读完这篇文章后,我明白了它respond_to是如何工作的(某种程度上),但我不明白它format在做什么。难道不应该是其中一个 format.html或format.json而不是两者吗?这两行实际上在做什么?
format.html { render :new }
format.json { render json: @student.errors, status: :unprocessable_entity }
Run Code Online (Sandbox Code Playgroud)
是不是有什么暗示if在里面?是不是像
if (format == html) {}
if …Run Code Online (Sandbox Code Playgroud)