簡體   English   中英

淘汰賽輸入綁定不起作用

[英]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函數獲取它。 因此,這意味着輸入框綁定不起作用。 知道為什么輸入綁定不起作用嗎?

您不需要解開綁定中的可觀察對象,請嘗試“ value:$ root.rootData.Page”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM