に従ってください。自分で試してみましたが、何か問題が発生しました。noob issueについて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
はここの正しいインスタンスを参照しているようだ。誰かが私の問題を指摘できますか?
ahh ... enlighteningが参照されます。 ..ありがとう@ニコ。私はそれを試しに行くよ。 – goh
質問..なぜ私のエラーメッセージがこれをdomwindowとして渡してくれないのですか? – goh
申し訳ありません、あなたはそれを言い換えることができますか? 「これ」がドームウィンドウオブジェクトであるとあなたはどこで期待していますか? – Niko