-1

我在敲除“With”绑定时遇到问题。我可以绑定。我可以绑定嵌套对象没问题,但不能绑定嵌套模型。我做错了还是这超出了“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/

4

3 回答 3

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());

http://jsfiddle.net/ash_bars/qNdUK/1/

于 2013-06-13T09:12:07.960 回答
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());

http://jsfiddle.net/jaq316/K4EU5/1/

于 2013-06-13T12:10:41.583 回答
-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());
于 2013-06-13T06:10:18.573 回答