【发布时间】:2013-02-06 06:47:37
【问题描述】:
我正在一个小型示例应用程序上学习 ember.js,但最后一部分我无法开始工作。
我有一个“俏皮话”(推文)列表,并且有一个文本输入字段允许创建一个新字段。提交新推文后,我想清除文本输入,但无济于事。在这一点上,我基本上逐字复制了todomvc example,它在那里工作(我什至使用相同的 ember.js 和 ember-data.js 版本来排除这种可能性)。
这是模板:
<script type="text/x-handlebars" data-template-name="index">
<h2>Latest Quips</h2>
<div>
{{view Ember.TextField id="new-quip" placeholder="Enter your Quip"
valueBinding="newQuip" action="createQuip"}}
</div>
相应控制器中的操作:
App.IndexController = Ember.ArrayController.extend({
createQuip: function() {
App.Quip.createRecord({
text: this.get('newQuip'),
user: 'ree'
});
this.set('newQuip', ''); // this row should clear the view
this.get('store').commit();
}
});
为了完整起见,模型:
App.Quip = DS.Model.extend({
text: DS.attr('string'),
user: DS.attr('string')
});
App.Store = DS.Store.extend({
revision: 11,
adapter: 'App.QuipsAdapter'
});
App.Quip.FIXTURES = [
{ id: 1, user: 'ree', text: 'Which is the best JS MVC?' },
{ id: 2, user: 'baaz', text: '@ree Definitely Ember.js!' }
];
App.QuipsAdapter = DS.FixtureAdapter.extend({});
应用程序runs here。
如果有人能指出我做错了什么,我会非常高兴。
谢谢,
巴林特
【问题讨论】:
-
我没有使用过 emberdata,纯 ember 的东西看起来相当正确。我已经在没有持久性的情况下对您的概念进行了基本测试,并且它按预期清除了该领域。对我来说看起来有点奇怪的一件事是你在清理完场地后提交了商店......但我不明白这会如何导致你的问题。 (另外,this.get('store').commit() 成语不在指南中……但是很多东西都没有)
-
是的,我浪费了几个小时来遵循指南中的代码和建议以及结果证明是为 Ember 0.9.x 编写的项目。最终似乎可行的是遵循 todomvc 示例,因为该示例已针对 1.0.pre 进行了更新?只要我的应用程序不比 todolist 应用程序复杂,它就可以工作:)
标签: ember.js