跟随文档,尝试我自己的并碰到一些问题。noob问题关于knockout.js和范围
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
似乎指的是这里的正确实例。有人能指出我的问题吗?
啊......启发。 ..谢谢@妮可。我会去尝试一下。 – goh
问题..为什么我的错误消息在Chrome中不能通过这个domwindow呢? – goh
对不起,您可以重新解释一下吗?你期望“这个”成为domwindow的目标吗? – Niko