-1

ノックアウト「ウィズ」バインディングで困っています。バインドできます。ネストされたオブジェクトは問題なくバインドできますが、ネストされたモデルはバインドできません。私はそれをすべて間違っていますか、それとも「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 に答える