我試圖擴大實體創建一個計算觀察到的,需要一個導航屬性導航屬性:擴展實體創建一個計算觀察到的,需要
app.domain.indicador = function() {
this.ValorMetaActual = ko.computed({
read: function() {
console.log(this.ValoresMeta); //navigation property: undefined
return 0;
},
deferEvaluation: true
}, this);
};
的問題是,當觀察到的是創建,導航屬性不存在。
我能做些什麼來解決這個問題?
「indicador」是一個entityType構造函數嗎?您是否考慮過註冊初始化程序來定義計算?依賴導航屬性將在調用初始化程序時定義。 – Ward
indicador是一個entityType,是的。按照此處的說明擴展實體:http://www.breezejs.com/documentation/extending-entities(Section:Add Knockout computeds)並在metadataStore(store.registerEntityTypeCtor(「Indicador」,app.domain。 indicador);)。我有其他擴展的實體可以正常使用。這是我第一次嘗試在計算的observable中使用導航屬性。如果它是相關的,變量ValoresMeta是一個集合。明天我可以提供更多的代碼(下午09:46 :)) –
您在Breeze KO模型庫中發現了一個微妙的錯誤。我們正在修復它。感謝您找到它。同時,如果它在初始化器中,你的邏輯應該可以工作。或者至少在我模仿你的例子時起作用。當我們修復構造函數的問題時,我們會在這裏告訴你。 – Ward