开发者

Is there a way to find out which variables in a knockout model are currently bound to the DOM?

Is there a way to get a list of variables in a knoc开发者_Python百科kout model that are currently bound to the DOM?

Alternatively, is there a way to query a variable and find out if changing it would lead to a change in the DOM?


Using Knockout 1.3 beta, you can use ko.dataFor(element) to return the data that would be bound against the element at that level.

This means that if you had an object like:

var myObject = { id: 1, name: "Bob" }

and bound it to an element

<div id="myElement" data-bind="text: name"></div>

ko.dataFor(document.getElementById("myElement")) would return myObject and not just the name.

Prior to 1.3, inside of a jQuery Template, you can use tmplItem to return this type of data.

There is not really a way to programmatically determine if changing an observable will specifically alter a certain element.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜