且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Knockout.js - 传递参数

更新时间:2023-11-30 23:03:46

单击绑定接受单击控件时要调用的回调函数。

The click binding accepts a callback function to be called when the control is clicked.

但是在您的示例中,您正在调用该函数。所以每次加载页面时都会发生这种情况,加载绑定并在编写函数时调用它。你需要将它包装在一个函数中,这样它就不会被调用。

However in your example, you are calling the function instead. So what happens is every time the page is loaded, the bindings are loaded and your function is invoked as it is written. You need to wrap that in a function so it doesn't get called like that.

<span class="user-box-name"
      data-bind="text: username, click: function () { $root.userClick(username); }">
</span>