我有一个需要用户输入apiKey
. 使用该表单数据,我将其传递给我的deals
路线,然后根据输入的apiKey
.
我的问题是,当我在 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>