0
我有我的路線設置爲Emberjs模型查找方法不填充模板
# 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)
)
當我去的路線「/」我得到的所有「警報實例」的列表,我點擊一個和它顯示單個「警報實例」的詳細信息。
我的模型對象設置如下。
# 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對象。
任何想法?