2015-07-01 51 views
0

從該代碼片斷:誰定義了「商店」對象?

Todos.TodosController = Ember.ArrayController.extend({ 
    actions: { 
    createTodo: function() { 
     // Get the todo title set by the "New Todo" text field 
     var title = this.get('newTitle'); 
     if (!title.trim()) { return; } 

     // Create the new Todo model 
     var todo = this.store.createRecord('todo', { 
     title: title, 
     isCompleted: false 
     }); 

     // Clear the "New Todo" text field 
     this.set('newTitle', ''); 

     // Save the new model 
     todo.save(); 
     } 
    } 
}); 

是,事實上,從Ember website

誰定義(和其中所定義的)this.store?我查看了Controller classDSL

回答

2

store是一個Ember Data簿記對象。

已通過Ember的Dependency Injection API注入到你的應用程序的控制器和使用Initializer路線,以便它可以從任何路徑或控制器被引用爲this.store

store始終是「存儲相同的實例:主'不管它從何處被調用,因爲它已被注入。