0
我希望「類別」中的每個模型都顯示其子類'{category//'內的'workflow'的{{workflowtype}}屬性。Emberjs爲模型(類)提供其子類的屬性
這些都是錯誤的,我得到:
Assertion failed: The value that #each loops over must be an Array. You passed
<VpcYeoman.Category:ember654:4> (wrapped in (generated category controller)) ember.js:417
Uncaught TypeError: Object [object Object] has no method 'addArrayObserver'
,這裏是我的代碼。我已經把代碼提到頂部的「工作流程」。
category.hbs
<h2>Category: {{permittype}}</h2><br>
<img class="department-add-icon" src="images/plus-blue.png">
<table class="table table-hover table-responsive sml-margin-left">
<h4>Workflow Type</h4>
{{input type="text" value=newWorkflowtype placeholder="Create a workflow and press enter" action="createWorkflow"}}
<table>
{{#each}}
<tr {{bind-attr class="isCompleted:completed"}}>
<td>
<input type="checkbox" class="toggle">
<label>{{workflowtype}}</label>
</td>
</tr>
{{/each}}
</table>
VpcYeoman.CategoriesRoute = Ember.Route.extend({
model: function() {
return this.store.find('category');
return this.store.find('workflow');
}
});
VpcYeoman.Category = DS.Model.extend({
permittype: DS.attr('string'),
isCompleted: DS.attr('boolean'),
classNameBindings: ['isAdministrator']
});
VpcYeoman.Workflow = VpcYeoman.Category.extend({
workflowtype: DS.attr('string')
})
VpcYeoman.Category.FIXTURES = [
{
id: 1,
permittype:'Building'
},
{
id: 2,
permittype:'Electrical'
},
{
id: 3,
permittype:'Zoning'
},
{
id: 4,
permittype:'Fire'
}
];
也很好奇我怎麼會在興業類中顯示的子類的屬性。
VpcYeoman.CategoriesController = Ember.ArrayController.extend({
actions: {
createCategory: function() {
var permittype = this.get('newPermittype');
if (!permittype.trim()) {return;}
var category = this.store.createRecord('category', {
permittype: permittype
});
this.set('newPermittype', '');
category.save();
},
createWorkflow: function() {
var workflowtype = this.get('newWorkflowtype');
if (!workflowtype.trim()) {return;}
var workflow = this.store.createRecord('workflow', {
workflowtype: workflowtype
});
this.set('newWorkflowtype', '');
workflow.save();
}
}
});
<h2>New Category</h2>
{{input type="text" value=newPermittype placeholder="Create a category and press enter" action="createCategory"}}
<table>
{{#each}}
<tr {{bind-attr class="isCompleted:completed"}}>
<td>
<input type="checkbox" class="toggle">
<label>{{#linkTo 'category' this}}{{permittype}}{{/linkTo}}</label>
</td>
</tr>
{{/each}}
</table>
VpcYeoman.Router.map(function() {
this.resource('categories', { path: '/categories' });
this.resource('category', { path: '/category/:category_id' });
});
你釘它。我現在正在收到「未捕獲的錯誤:沒有任何事件處理事件'createWorkflow'」,但在我問之前,我會再次查看我的代碼。 –