2015-03-31 84 views
0

我有一个输入框,我将它的值绑定到我的viewmodel中的一个值。但它没有约束力。我不知道为什么。敲除输入绑定不起作用

这是输入框标记:

<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函数中得到它。所以这意味着输入框绑定不起作用。任何想法为什么输入绑定不起作用?

回答

1

您不需要展开绑定中的observable,请尝试“value:$ root.rootData.Page”

+0

太棒了!它的作品,我会接受它作为一个正确的答案。谢谢。 – Obviously 2015-03-31 20:59:10

+0

非常感谢,很高兴它为你工作。 – tcigrand 2015-03-31 21:05:29