我有一個意外的行爲,也許你可以讓我明白那裏存在的問題。我認爲這是一個功能,但我無法理解它。ember.js:控制器的意外行爲
路線:
App.LacesRoute = Ember.Route.extend
model: -> App.Lace.find()
App.LaceRoute = Ember.Route.extend
model: (params) ->
App.Lace.find(params.lace_id)
setupController: (controller, model)->
controller.set('content', model)
控制器:
App.LacesController = Ember.ArrayController.extend
contentCount: (
-> @get("content").toArray().length
).property("content")
列表模板:
{{contentCount}}
{{#each controller}}
{{this}}
{{/each}}
詳細信息模板這裏ininfluent
路由器:
@resource "laces", ->
@resource "lace", {path: ":lace_id"}
當我訪問/laces
計數打印0,但所有的鞋帶在each
上市當我訪問/laces/1
計數打印出正確的數量和鞋帶正確列出
它的工作原理。請問你或任何人解釋我爲什麼? –
@VecchiaSpugna我用更多的信息更新了答案。我希望它有幫助。 –
謝謝。不幸的是,我認爲改變內容也會影響其長度 –