2012-12-11 70 views
1

我試圖擴大實體創建一個計算觀察到的,需要一個導航屬性導航屬性:擴展實體創建一個計算觀察到的,需要

app.domain.indicador = function() { 
    this.ValorMetaActual = ko.computed({ 
     read: function() { 
      console.log(this.ValoresMeta); //navigation property: undefined 
      return 0; 
     }, 
     deferEvaluation: true 
    }, this); 
}; 

的問題是,當觀察到的是創建,導航屬性不存在。

我能做些什麼來解決這個問題?

+0

「indicador」是一個entityType構造函數嗎?您是否考慮過註冊初始化程序來定義計算?依賴導航屬性將在調用初始化程序時定義。 – Ward

+0

indicador是一個entityType,是的。按照此處的說明擴展實體:http://www.breezejs.com/documentation/extending-entities(Section:Add Knockout computeds)並在metadataStore(store.registerEntityTypeCtor(「Indicador」,app.domain。 indicador);)。我有其他擴展的實體可以正常使用。這是我第一次嘗試在計算的observable中使用導航屬性。如果它是相關的,變量ValoresMeta是一個集合。明天我可以提供更多的代碼(下午09:46 :)) –

+0

您在Breeze KO模型庫中發現了一個微妙的錯誤。我們正在修復它。感謝您找到它。同時,如果它在初始化器中,你的邏輯應該可以工作。或者至少在我模仿你的例子時起作用。當我們修復構造函數的問題時,我們會在這裏告訴你。 – Ward

回答

1

這是一個錯誤,已在v 0.76.3中修復。請讓我們知道這是否解決了您的問題。 ...並感謝您找到它。

0

我假設的問題是,你的計算值顯示在頁面上的某個地方 - 並且未定義。如果您將導航屬性(this.ValoresMeta)設置爲可觀察值,則只要最終分配了ValoresMeta,Knockout就會更新顯示值ValorMetaActual

app.domain.indicador = function() { 
    this.ValoresMeta = ko.observable(0); 
    this.ValorMetaActual = ko.computed({ 
     read: function() { 
      console.log(this.ValoresMeta()); 
      return 0; 
     }, 
     deferEvaluation: true 
    }, this); 
}; 

上述代碼將0指定爲ValoresMeta的默認值。你可能需要一些其他的默認值,但你應該有一些默認值,這樣你的計算不會像未定義的那樣結束。

相關問題