具有约束性问题的淘汰赛

时间:2013-06-13 06:02:27

标签: knockout.js

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

3 个答案:

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

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

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

请参阅http://jsfiddle.net/jaq316/K4EU5/1/

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