うまくいかない非常に単純な例があります。
jsfiddle: http://jsfiddle.net/ThomasDeutsch/8hzhp/3/
// My Model
function Customer(id, name, lastname) {
this.Id = ko.observable(id);
this.Name = ko.observable(name);
this.LastName = ko.observable(lastname);
}
// My ViewModel
ViewModel = (function () {
var getName = ko.computed(function (x) {
return x.Name();
});
return {
getName: getName(new Customer(1, "Thomas", "D"))
};
})();
ko.applyBindings(ViewModel);
問題:パラメータ (x) が定義されていません
目標:呼び出されたオブジェクトの Name-Property を返します - x をプロパティとして使用して、監視可能な Name プロパティを持つ任意のオブジェクトでこの関数を呼び出すことができるようにします
コードの説明: これは、knockout.js を含む Revealing-module-pattern を使用して行われます。Name-property は ko.observable() であるため、() が必要です。
質問: x が定義されていないのはなぜですか?