我有一個Ember.js(1.0.0)應用程序,我試圖實現內置的Ember.Select
視圖。Ember.Select視圖抱怨通過的值
該應用程序顯示了三個任務列表:inProgress
,completed
和unassigned
。用戶可以過濾相應項目顯示的任務。這就是Ember.Select
視圖進來。然而,當我加載路線,灰燼向我吠叫約的價值,我給它的類型:
Assertion failed: The value that #each loops over must be an Array. You passed projects.all
Uncaught TypeError: Object projects.all has no method 'addArrayObserver'
Uncaught Error: Something you did caused a view to re-render after it rendered but before it was inserted into the DOM.
我一直在摔跤幾個小時,嘗試下面的代碼不同的排列 - 我知道我必須丟失的東西明顯,因爲它只是不能難以獲得這樣一個簡單的組件來正常工作。希望你們能指引我朝正確的方向發展。
這裏是我的路線:
Bee.TasksIndexRoute = Bee.Auth.Route.extend
setupController: (ctrl) ->
# get tasks
Bee.Auth.send
url: Bee.endpoint "/tasks"
.done (tasks) ->
ctrl.set "tasks.all", tasks
# get projects
Bee.Auth.send
url: Bee.endpoint "/projects"
.done (projects) ->
ctrl.set "projects.owned", projects.owned
ctrl.set "projects.participating", projects.participating
ctrl.set "projects.all", projects.owned.concat projects.participating
這裏是我的控制器:
Bee.TasksIndexController = Ember.ObjectController.extend
project: null
content:
tasks:
all: []
inProgress: []
completed: []
unassgined: []
projects:
all: []
owned: []
participating: []
visible: (->
ctrl = @
# filter tasks here
).property "project"
這裏是我的模板:
<script type="text/x-handlebars" id="tasks/index">
<div class="center-pane">
<div class="top_options">
<div class="project_filter">
<strong>Viewing: </strong>
{{view Ember.Select
content=projects.all
optionValuePath='content._id'
optionLabelPath='content.title'
value=project
prompt='All Tasks'
}}
</div>
<strong class="gold-gradient option_button">
{{#link-to 'tasks.create' classNames='new_task'}}Create Task{{/link-to}}
</strong>
</div>
<div class="col3">
<div class="col-header in-progress light-gradient">
<h3>In Progress</h3>
</div>
<div id="tasks_active_list">
{{#if visible.inProgress.length}}
<ul>{{#each visible.inProgress}}{{view Bee.TaskListView}}{{/each}}</ul>
{{else}}
<p class="no_projects">None</p>
{{/if}}
</div>
</div>
<div class="col3">
<div class="col-header completed light-gradient">
<h3>Completed</h3>
</div>
<div id="tasks_closed_list">
{{#if visible.completed.length}}
<ul>{{#each visible.completed}}{{view Bee.TaskListView}}{{/each}}</ul>
{{else}}
<p class="no_projects">None</p>
{{/if}}
</div>
</div>
<div class="col3">
<div class="col-header unassigned light-gradient">
<h3>Unassigned</h3>
</div>
<div id="tasks_unassigned_list">
{{#if visible.unassigned.length}}
<ul>{{#each visible.unassigned}}{{view Bee.TaskListView}}{{/each}}</ul>
{{else}}
<p class="no_projects">None</p>
{{/if}}
</div>
</div>
</div>
</script>
任何有識之士將非常感激。我不知道Ember.Select
是罪魁禍首,因爲當我用一個簡單的替換:
<select>
{{#each projects.all}}
<option value="{{_id}}">{{title}}</option>
{{/each}}
</select>
...它呈現很好 - 但是我需要使用Ember.Select
這樣我就可以值綁定到project
財產在TasksIndexController
- 因爲我會用它作爲可見的函數來觸發visible
函數。
從'[]''來似乎null'沒有改變有所作爲,看着我一看,原來是用灰燼1.1 JSBin例如但是後.1 - 所以我更新了我的1.0.0版本到最新的1.1.2版本,並且所有內容都按我的預期工作。多麼痛苦!感謝間接回答! – sp0rkyd0rky
謝謝@ sp0rkyd0rky!這讓我瘋狂!我最初從1.1.1開始,但用一段時間來測試一些功能。我最近回到1.1.1並得到這個錯誤。 – Jmorvan