在ember.js文件我已經找到了下一個:Ember.js和選擇多個模型刪除
控制器,讓你與顯示邏輯裝點您的模型。在一般情況下,您的模型將被保存到服務器的屬性,而控制器將有你的應用程序並不需要保存到服務器的性能。
我嘗試添加「選擇」功能,我的應用程序。
這裏是的jsfiddle:http://jsfiddle.net/JWf7X/
似乎濾波器特性由模型濾波,而不是由控制器(因爲執行console.log爲空)。
this.filterProperty('isSelected', true); //managing models
如何正確寫入removeSelected動作?
是正確的方式在控制器存儲「isSelected」?我想加入isSelected的模型是不正確的做法,因爲這個屬性不會從服務器通過REST API加載並不會被保存到它。
的application.js:
window.App = Ember.Application.create();
App.ApplicationAdapter = DS.FixtureAdapter.extend();
App.Test = DS.Model.extend({
title: DS.attr('string'),
});
App.Test.FIXTURES = [
{
id: 1,
title: 'Learn Ember.js',
},
{
id: 2,
title: '...',
},
{
id: 3,
title: 'Profit!',
}
];
App.IndexRoute = Ember.Route.extend({
model: function() {
return this.get('store').find('test');
}
});
App.IndexController = Ember.ArrayController.extend({
actions: {
removeSelected: function() {
var selected = this.filterProperty('isSelected', true);
console.log(selected);
}
},
});
App.TestController = Ember.ObjectController.extend({
isSelected: false,
});
的index.html:
<script type="text/x-handlebars" data-template-name="index">
<button {{action "removeSelected"}}>remove selected</button>
<ul>
{{#each itemController="test"}}
<li>
{{input type="checkbox" checked=isSelected}}
<label>{{title}}</label>
</li>
{{/each}}
</ul>
</script>
日Thnx的幫助。我錯誤地認爲在每個助手中設置itemController會將其設置爲IndexController。 –
不客氣。只是在我的答案更新,'每個itemController =「測試」'是不需要'每個'。小提琴是正確的。 –