敲除输入绑定不起作用
Knockout input binding not working
我有一个输入框,我正在将它的值绑定到我的视图模型中的一个值。但它不具有约束力。我不知道为什么。
也就是输入框标记:
<input data-bind="value : $root.rootData.Page(), valueUpdate:'afterkeydown'" class="form-control" placeholder="Jump to ...">
这里我将用户输入的值发送到我在 JS 中的函数:
<button type="button" class="btn btn-default" data-bind="click: $root.selectPage.bind($root, $root.rootData.Page())"> Search! </button> // This does not works
<button type="button" class="btn btn-default" data-bind="click: $root.selectPage.bind($root, parseInt(7))"> Search! </button> // This works, I get 7 at the JS function.
在 JS 函数中,我正在获取旧值。如果我发送一个常量值,例如 7,它会起作用,并且我会在我的 JS 函数中获取它。所以这意味着输入框绑定不起作用。知道为什么输入绑定不起作用吗?
你不需要解开绑定中的 observable,尝试 "value:$root.rootData.Page"
我有一个输入框,我正在将它的值绑定到我的视图模型中的一个值。但它不具有约束力。我不知道为什么。
也就是输入框标记:
<input data-bind="value : $root.rootData.Page(), valueUpdate:'afterkeydown'" class="form-control" placeholder="Jump to ...">
这里我将用户输入的值发送到我在 JS 中的函数:
<button type="button" class="btn btn-default" data-bind="click: $root.selectPage.bind($root, $root.rootData.Page())"> Search! </button> // This does not works
<button type="button" class="btn btn-default" data-bind="click: $root.selectPage.bind($root, parseInt(7))"> Search! </button> // This works, I get 7 at the JS function.
在 JS 函数中,我正在获取旧值。如果我发送一个常量值,例如 7,它会起作用,并且我会在我的 JS 函数中获取它。所以这意味着输入框绑定不起作用。知道为什么输入绑定不起作用吗?
你不需要解开绑定中的 observable,尝试 "value:$root.rootData.Page"