我遇到了“淘汰”的问题。我可以绑定。我可以绑定嵌套对象没问题,但不能嵌套模型。我做错了还是超出了“with”绑定范围。
var viewModel = function(){
var self = this;
self.anObject = {
test: ko.observable("I'm and object bound by WITH.")
}
var aFunction = function (){
var self = this;
self.test = ko.observable("I would like to be bound by WITH");
}
};
ko.applyBindings(new viewModel());
这是我的小提琴http://jsfiddle.net/t3T5N/1/
答案 0 :(得分:2)
var viewModel = function(){
var self = this;
self.anObject = {
test: ko.observable("I'm and object bound by WITH.")
}
self.aFunction =ko.computed(function (){
var self = this;
self.test = ko.observable("I would like to be bound by WITH");
return self.test;
})
};
ko.applyBindings(new viewModel());
答案 1 :(得分:1)
var viewModel = function(){
var self = this;
self.anObject = {
test: ko.observable("I'm and object bound by WITH.")
}
self.aFunction = function (){
var thisfunc = this;
thisfunc.test = ko.observable("I would like to be bound by WITH");
return thisfunc;
}
};
ko.applyBindings(new viewModel());
答案 2 :(得分:-1)
var viewModel = function(){
var self = this;
self.anObject = {
test: ko.observable("I'm and object bound by WITH.")
}
var ViewModel2 = function (){
var self = this;
self.test = ko.observable("I would like to be bound by WITH");
};
self.aFunction = new ViewModel2();
};
ko.applyBindings(new viewModel());