这是我的小提琴链接。请帮帮我。 http://jsfiddle.net/KLXN5/Knockout.js:访问子模型属性
var Person = function(first, last)
{
var self = this;
this.FirstName = first;
this.Children = ko.observable(new Children(last));
}
我需要访问Children.LastName
财产。
这是我的小提琴链接。请帮帮我。 http://jsfiddle.net/KLXN5/Knockout.js:访问子模型属性
var Person = function(first, last)
{
var self = this;
this.FirstName = first;
this.Children = ko.observable(new Children(last));
}
我需要访问Children.LastName
财产。
您应该使用with
设置方面,这将允许访问儿童:
<div data-bind="text: FirstName"></div>
<div data-bind="with: Children">
<div data-bind="text: LastName"></div>
</div>
我可以推荐你签我约束力的公约库,其在配置库KO公约,并带走最头疼的问题与绑定和上下文,
对于示例
<div>
<div data-name="FirstName"></div>
<div data-name="Children.LastName"></div>
</div>
If you have more than one property you want to access its better todo
<div>
<div data-name="Children">
<div data-name="LastName"></div>
</div>
</div>
https://github.com/AndersMalmgren/Knockout.BindingConventions/wiki
感谢您的建议。我会看看。 – dineshd87
如果从内部访问的人这个尝试这样的事情。
//To Access the current value
var x = this.Children().LastName()
//To edit the current value
this.Children().LastName("Some new value")
我知道它应该很简单。是的,它非常有用,非常感谢。 – dineshd87
@ dineshd87不客气。如果这有帮助 - 随时接受答案;) –
对不起!我没有声誉来标记你的答案是正确的。 – dineshd87