0

ルートを次のように設定しています

# ROUTER MAPPING
App.Router.map( ->
  this.resource("alertInstances", 
    path:"/"
  )

  this.resource("alertInstance", 
    path:"/:alertInstance_id"
  )
)

# ALERT INSTANCES ROUTE
App.AlertInstancesRoute = Ember.Route.extend(
  model: ->
    App.AlertInstance.all()

  setupController: (controller, model) ->
    controller.set("content", model)
)

# ALERT INSTANCE ROUTE
App.AlertInstanceRoute = Ember.Route.extend(
  model: (params) ->
    App.AlertInstance.find(params.alertInstance_id)

  setupController: (controller, model) ->
    controller.set("content", model)
)

ルート「/」に移動すると、すべての「アラートインスタンス」のリストが表示され、1つをクリックすると、単一の「アラートインスタンス」の詳細が表示されます。

私のモデルオブジェクトは次のように設定されています。

# ALERT INSTANCE MODEL
App.AlertInstance = Ember.Object.extend()
App.AlertInstance.reopenClass(
  allAlertInstances: []
  currAlertInstance:null
  all: ->
    @allAlertInstances = []
    $.ajax
      url:base + "api/alert_instances"
      dataType: "JSON"
      context:this 
      success: (response) ->
    for i in response
      i.clinical = if i.alert_type is "clinical" then true else false
      @allAlertInstances.addObject App.AlertInstance.create(i)
    @allAlertInstances
)

これはすべて非常にうまく機能します。ただし、ユーザーが直接「/ 10」に移動すると(アラートインスタンスIDを指定して)、サーバーからデータが取得されていないため、何も表示されません。

そこで、次の「検索」メソッドを追加しました

find: (id) ->
  @currAlertInstance = null
  $.ajax 
    url:base + "api/alert_instance"
    dataType:"JSON"
    context:this
    data:
      id:id
      success: (response) ->
        @currAlertInstance = App.AlertInstance.create(response)
        @currAlertInstance
  @currAlertInstance

ただし、ビューは空で、何も表示されません。

Chromeコンソールネットワークで、単一のアラートインスタンスのJSONオブジェクトが実際に返されたことがわかります。

何か案は?

4

1 に答える 1

0

テンプレートをレンダリングするには、Route で render を使用します。

App.AlertInstancesRoute = Ember.Route.extend({
  render: function() {
    this.render([<handlebar_name>], {
       [outlet: <outlet_name>],
       [into: <template_name_to_render_to>]
    });
  },

  model: function(params) {
    App.AlertInstance.all();
  },

  setupController: function(controller, model) {
    controller.set("content", model);
  }
})

詳細については、このリンクをたどってください

于 2013-03-05T09:35:10.497 に答える