2016-01-20 23 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

相关问题