转换到当前路线时,不会重新评估Ember模型挂钩

时间:2014-10-02 15:17:36

标签: ember.js routing coffeescript

我有一个主要的详细信息视图,如下面的模型显示:

enter image description here

左侧的插座(主视图)包含索引路径。右侧的插座包含演出路线。

“小部件”是对象控制器的内容属性中保存的核心模型。还加载了另外两个模型,它们通过model在路径的Ember.RSVP.hash钩子中获取,然后分配到setupController中的控制器属性。

所以这一切都很有效,但是当我选择左侧的新小部件时,我遇到了一个问题。 URL使用新的ID动态段更新,但不评估模型挂钩。它直接进入设置控制器,现在模型值未定义。它没有进入任何中间路线。

App.WidgetsShowRoute = Ember.Route.extend

  # Query Params for managing the paginated tables
  queryParams:
    someInfoPageSize:
      refreshModel: true
    someInfoPage:
      refreshModel: true
    otherPageSize:
      refreshModel: true
    otherPage:
      refreshModel: true

  model: (params) ->
    console.log "Give me some models!"
    @modelFor('widgets') # Get make sure the master route has loaded
    store = @get('store')
    store.find("widget", params.widget_id).then (result) ->
      promises = {
        widget: result
        info: store.findQuery("some_info", {
          group_id: result.get('widgetId')
          per_page: params.someInfoPageSize or 10
        })
        other_info: store.findQuery("other_info", {
          name: result.get('name')
          per_page: params.otherPageSize or 10
          page: params.otherPage or 1
        })
      }
      Ember.RSVP.hash(promises)

  setupController: (controller, models) ->
    console.log "Setting Up Controller"
    infoMeta = @store.metadataFor("some_info")
    otherMeta = @store.metadataFor("other_info")
    console.log "content should be #{models.widget.get('name')}"
    controller.setProperties
      content: models.widget
      someInfo: models.some_info
      groupAccount: models.other_info
      # ... a bunch of different metadata assignments from the service

  resetController: (controller, isExiting, transition) ->
    # tried resetting all the properties here to no avail, didn't affect model hook being called

  actions:
    willTransition: (transition) ->
      # hooking into this to set loading state on tables
      @controller.setProperties
        infoLoading: true
        otherLoading: true

      # tried calling to super in case that affected the model hook being called.
      @_super(transition)

0 个答案:

没有答案