ドキュメントに従い、自分で試して、問題にぶつかりました。
initializeViewModel = function(){
var listing_model = {
sale_rent: ko.observable( jQuery('#id_sale_rent')),
property_type: ko.observable( jQuery('#id_property_type').val()),
address: ko.observable( jQuery('#id_address')),
is_condo: ko.computed(function(){
return this.property_type() == 'condominium';
}, this)
};
listing_model.district = ko.computed(function(){
return this.district() || this.property_type();
}, listing_model);
return listing_model;
}
ステートメントreturn this.property_type() == 'condominium';
は例外を引き起こしますobject <object> has no method property_type()
。これはスコープの問題かもしれないと思いますが、this
ここでは正しいインスタンスを参照しているようです。誰かが私の問題を指摘してもらえますか?