2015-05-21 80 views
1

我想知道如何使用来自不同控制器的参数刷新模型。基本上我想刷新基于参数的列表模型。参数“readstatus”实际上是FilterbuttonController中的“Filter”的值。单击按钮时刷新模型

当你点击li时,模型应该刷新。我知道这似乎不正确,但这就是现在应用程序的工作方式,我必须找到一种方法。有什么建议么?代码如下。谢谢。

我有一个模型:

App.ListRoute = Ember.Route.extend({ 

    model: function(readStatus){ 
     return this.store.find('list', { status : readStatus}); 
} 

我有一个模板:

<script type="text/x-handlebars" data-template-name="filterbutton">  
    <div class="filter-dropdown dd"> 
     <button class="filter" {{ action 'toggleDd'}}><span id="current_text">{{ filter }}</span> &#xf107;</button> 
     {{#if ddVisible}}   
      <ul class="dropdowns"> 
       <li {{ action 'filterConversations' 'All'}}></li> 
       <li {{ action 'filterConversations' 'Opened'}}><</li> 
       <li {{ action 'filterConversations' 'Closed'}}></li> 
       <li {{ action 'filterConversations' 'Unread'}}></li> 
       <li {{ action 'filterConversations' 'Read'}}></li> 
      </ul> 
     {{/if}} 
    </div> 
</script> 

此模板使用下列控制器相关:

App.FilterbuttonController = Ember.Controller.extend({ 

    ddVisible: false, 
    filter: "Filter", 

    actions: { 

     toggleDd: function(){ 
      if (this.ddVisible){ 
       this.set('ddVisible', false); 
      } 
      else{ 
       this.set('ddVisible', true) 
      } 
     }, 

     filterConversations: function(chosenFilter){ 
      this.send('toggleDd'); 
      this.set('filter', chosenFilter); 

      **//This is where the refreshing should be with the value of filter** 

     }   
    } 
}); 

回答

0
this.refresh(); 

应该是所有这是需要刷新。

export default Ember.Route.extend({ 
    queryParams: { 
    SOME_PARAM: { 
     refreshModel: true 
    } 
    }, 
    model: function(params){ 
    console.log(params.SOME_PARAM); 
    } 
}); 

也可以添加到路由表示查询参数是相关的,应该刷新每当查询参数的变化。所以我想你可以改变你的查询参数,模型会自动刷新。

http://guides.emberjs.com/v1.10.0/routing/query-params/

+0

感谢您的信息。我应该在哪里指定必须使用新的readStatus参数进行刷新? – greenymaster69

+0

第二个片段将进入您的路线。 – carter

+0

谢谢!一切正常 – greenymaster69