2016-01-20 28 views
0

我在嘗試更新模型值時出現問題,PendingActionController.updateStage方法被調用我需要它來更新相關模型&反映更新的值。如果我在PendingController中創建另一個方法,如ShowMessage,它將顯示警報。我應該如何從emberjs中的子控制器重新加載模型?

請解釋我應該使用什麼方法?

例如,以下是代碼:

<script type="text/x-handlebars" id="pending/_actions"> 
<div class="content-actions"> 
    <h2>Pending Actions</h2> 
    <ul> 
     {{#each pendingstages}} 
      <li> 
       {{#unless refreshingStage}} 
        {{render 'pendingAction' this}} 
       {{/unless}} 
      </li> 
     {{/each}} 
    </ul> 
</div> 
</script> 

<script type="text/x-handlebars" id="pendingAction">  
    <div class="actionsBox"> 
     <div class="actionsBar"> 
      <div {{bindAttr class=":actionStatus completed:blue:green"}} {{action updateStage this}}>&nbsp;</div> 
     </div> 
     <div class="clear-both"></div> 
    </div> 
</script> 

PendingController:

App.PendingController = App.BaseObjectController.extend(App.ActionsControllerMixin, { 
needs: ['application'], 
postRender: function() { 
    //Some code here.... 
}, 

pendingstages: function(){ 
    return App.PendingStage.find({Id: this.get('model.id')}); 
}.property('model.id', '[email protected]', 'refreshStage'), 

ShowMessage: function(){ 
    alert('Inside Sohw message.'); 
}, 
}); 

PendingActionController

App.PendingActionMixin = { 
    isEditing: false, 
    canDelete: true, 
    canEdit: true, 

    toggleIsEditing: function(){ 
     this.toggleProperty('isEditing'); 
    } 
}; 

App.PendingActionController = App.BaseObjectController.extend(App.PendingActionMixin, { 
    needs: 'pending', 
    postRender: function(){ 
     //some code here... 
    }, 

    updateStage: function(stage){ 
     var self = this; 
     this.get('controllers.pending').send('pendingstages');  
    }, 
}); 

EDIT(1): Followignt是灰燼&餘燼數據的版本: 餘燼-1.0.0-master.js 餘燼 - 數據 - master.js:CURRENT_API_REVISION:12

+0

你使用的是什麼版本的Ember和Ember-Data。? – kushdilip

+0

請參閱編輯(1): – user1400290

回答

0

問題可以通過使用store.fetch而不是store.find來解決。

store.fetch始終會調用API,無論該特定數據是否存在於本地餘燼數據存儲中。使用這樣的..

pendingstages: function(){ 
    return App.PendingStage.fetch({Id: this.get('model.id')}); 
}.property('model.id', '[email protected]', 'refreshStage'), 

ember-data/store.jscode。現在已棄用。但是你會發現新的方法,而不是這個。

+0

嗨,謝謝你的迴應。但我得到以下異常:獲取不是一個函數 – user1400290

相關問題