【发布时间】:2015-05-20 18:35:10
【问题描述】:
我正在尝试创建新记录并将其推送到商店。我可以很好地坚持它(一旦我弄清楚这一点,我会在成功坚持后推送到商店),但是视图/模板没有被刷新。我知道持久性是有效的,因为如果我刷新整个页面,就会出现新记录。
我也尝试了 this.store.push(),但没有任何反应。我环顾四周,似乎每个人都在使用 filter() 但仅在父控制器中的子记录集上使用...
在此先感谢,我觉得它非常基本。
路线/项目
export default Ember.Route.extend({
model: function(){
return this.store.find('projects');
}
});
控制器/项目
export default Ember.ArrayController.extend({
actions: {
createProject: function() {
var title = this.get('newProjectTitle');
var description = this.get('newProjectDescription');
if (!title.trim()) { return; }
// Create the new Project model
var project = this.store.createRecord('project', {
title: title,
description: description
});
project.save();
this.set('newProjectTitle', '');
this.set('newProjectDescription', '');
}
}
});
projects.hbs
<div class="form-group">
{{input type="text" class="form-control" placeholder="title" value=newProjectTitle}}
{{input type="text" class="form-control" placeholder="description" value=newProjectDescription action="createProject"}}
</div>
<button class="btn btn-xs btn-success" {{action 'createProject'}}>Create this Project</button>
<ul class="list-group">
{{#each project in model}}
{{#link-to 'project' project}}
<li class="list-group-item">
{{project.id}} - {{project.title}}
</li>
{{/link-to}}
{{/each}}
</ul>
【问题讨论】:
标签: ember.js view ember-data push