淘汰赛js将正确的参数传递给方法 [英] knockout js passing correct parameter to method

查看:72
本文介绍了淘汰赛js将正确的参数传递给方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在敲除中使用单击绑定时,敲除如何知道将正确的参数传递给与其绑定的方法?

when using the click bind in knockout, how does knockout know to pass the correct parameter to the method its bound to?

<div id="test" data-bind="click: runTest"/>
</div>


self.runTest = function (coolParameter){
doSomethingCool();
}

推荐答案

致电您的处理程序时,Knockout将提供当前模型 值作为第一个参数.如果您正在 为集合中的每个项目渲染一些UI,您需要知道 哪个项目的用户界面被点击.

When calling your handler, Knockout will supply the current model value as the first parameter. This is particularly useful if you’re rendering some UI for each item in a collection, and you need to know which item’s UI was clicked.

来自文档

文档中还存在一些有关如何通过添加包装函数来传递更多参数的讨论

There also is some discussion in the docs about how to pass more parameters by adding a wrapping function

<button data-bind="click: function(data, event) { 
    myFunction('param1', 'param2', data, event) 
}">
    Click me
</button>

这篇关于淘汰赛js将正确的参数传递给方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆