我有一個起始頁面,要求用戶輸入apiKey
。使用該表單數據,我將其傳遞給我的deals
路由,然後根據輸入的apiKey
獲取相關數據。將對象模型作爲單個對象傳遞給ArrayController
我的問題是,當我直接與URI的apiKey
加載交易頁面,它從形式start
頁面上會並與apiKey
提交的時候,我收到以下錯誤工作正常,但是,:
Uncaught Error: assertion failed: an Ember.CollectionView's content must implement Ember.Array. You passed 'asdf'
這裏是app.js:
App = Ember.Application.create();
App.Store = DS.Store.extend({
revision: 12,
adapter: 'DS.FixtureAdapter'
});
App.Deal = DS.Model.extend({
name: DS.attr('string')
});
App.Deal.FIXTURES = [
{id: 1, name: 'Deal 1'},
{id: 2, name: 'Deal 2'}
]
App.Router.map(function() {
this.resource('start', { path: '/' });
this.resource('deals', { path: '/deals/:api_key' });
});
App.StartController = Ember.ObjectController.extend({
apiKey: '',
getDeals: function (model) {
this.transitionToRoute('deals', this.apiKey);
}
});
App.DealsRoute = Ember.Route.extend({
model: function() {
// return App.Deal.getWonFor(params.api_key);
return App.Deal.find();
}
});
App.DealController = Ember.ArrayController.extend({
});
App.DealsView = Ember.View.extend({
didInsertElement: function() {
// Add active class to first item
this.$().find('.item').first().addClass('active');
this.$().find('.carousel').carousel({interval: 1000});
}
});
下面是HTML:
<script type="text/x-handlebars">
<h2>Won Deal Ticker</h2>
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="start">
{{view Em.TextField valueBinding="apiKey" placeholder="API Key" action="getDeals" }}
<br />
<button {{action 'getDeals' apiKey}} class="btn btn-large">Get Won Deals!</button>
</script>
<script type="text/x-handlebars" data-template-name="deals">
<div id="carousel" class="carousel slide">
<div class="carousel-inner">
{{#each model}}
<div class="item">
{{name}}
</div>
{{/each}}
</div>
</div>
</script>
你從控制檯發佈相同的錯誤信息?我看不到「asdf」來自 – MilkyWayJoe 2013-04-10 01:14:18
是的。 'start'視圖包含一個TextField,我使用'apiKey'鍵入「asdf」並使用它下面的按鈕進行提交。 – brandonhilkert 2013-04-10 01:48:04