淘汰模板中的 jquery SlideToggle() 函数
因此,如果我想调用带有淘汰赛的 data-bind="click: ShowHide" 的函数,我该怎么做? 请记住,数据绑定位于 li 元素上,该元素由模板填充。我的功能如下:
viewModel = {
LoadedReports: ko.observableArray([]),
ShowHide: function() {
$(this).children().slideToggle('slow');
}
}
在我的模板中,我有:
<li data-bind="click: ShowHide, clickBubble: false"><'children elements being populated'></li>
So if I wanted to call a function with knockout's data-bind="click: ShowHide" how would i go about that?
keep in mind the data-bind is on an li element, which is being populated by a template. my function was as follows:
viewModel = {
LoadedReports: ko.observableArray([]),
ShowHide: function() {
$(this).children().slideToggle('slow');
}
}
and within my template I have :
<li data-bind="click: ShowHide, clickBubble: false"><'children elements being populated'></li>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将 .ShowHide 函数放在表示 li 的对象上(我假设它是一个 LoadedReport 实例。)
将 .ShowHide 放在该对象上。或者,您可以将 .ShowHide 函数放在视图模型上,然后在绑定中使用 click: $root.ShowHide。
Put the .ShowHide function on the object that represents the li (I'm assuming it's a LoadedReport instance.)
Put the .ShowHide on that. Alternately, you can put the .ShowHide function on your view model, then in your binding, use click: $root.ShowHide.
很抱歉,如果有人觉得这个问题已经得到解答,但对我来说答案还不清楚。所以这是一个明显的例子:
与问题的区别在于我在这个例子中使用
标签而不是
。
Sorry if anyone feels that this is already answered, but to me the answer wasn't clear. So here is a clear example:
The difference from the question is simply that I am using
<div>
tags instead of<li>
for this example.前几天我自己也得到了这个。请参阅 Judah H. 对我必须做的事情的建议的评论。
Got this one myself the other day. See the comment on Judah H.'s suggestion for what I had to do.