1

I'm having trouble figuring out where the edit is being saved. It looks like when we make an edit, the edit is going directly into the Local Storage, and saved immediately. But the view's change method has no save() anywhere. Do you know how this magic is getting done?

change: function () {
    var value = this.get('value');

    if (Ember.isEmpty(value)) {
        this.get('controller').removeTodo();
    }
},

I'm looking at the source directly in the chrome source viewing.

4

1 回答 1

2

它在这一行完成:https ://github.com/tastejs/todomvc/blob/gh-pages/architecture-examples/emberjs/js/models/todo.js#L10

待办事项模型

Todos.Todo = DS.Model.extend({
  title: DS.attr('string'),
  isCompleted: DS.attr('boolean'),

  todoDidChange: function () {
    Ember.run.once(this, function () {
      this.get('store').commit();
    });
  }.observes('isCompleted', 'title')
});

基本上发生的情况是,正确的模型有一个观察者设置,当模型的属性发生变化时Todo会触发该函数。在该函数内部调用它将更改保存到本地存储。todoDidChangeisCompletedtitlethis.get('store').commit()

希望能帮助到你。

于 2013-09-05T23:14:56.360 回答