Ember.js并选择多个模型进行删除
Ember.js and selecting multiple models for deleting
在余烬中.js我接下来找到的文档:
控制器允许您使用显示逻辑装饰模型。通常,模型将具有保存到服务器的属性,而控制器将具有应用不需要保存到服务器的属性。
我正在尝试向我的应用程序添加"选择"功能。
这是jsfiddle:http://jsfiddle.net/JWf7X/
似乎过滤器属性是按模型而不是按控制器过滤的(因为控制台.log为空)。
this.filterProperty('isSelected', true); //managing models
如何正确编写删除所选操作?
在控制器中存储"isSelected"的正确方法是什么?我认为为模型添加 isSelected 不是正确的方法,因为此属性不会通过 REST API 从服务器加载,也不会保存到服务器中。
应用.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,
});
索引.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>
在每个视图帮助程序中使用 itemController
查找源。将创建一个新的阵列控制器,而不是使用您的IndexController
。所以isSelected
不会出现在IndexController
里面.
如果您将itemController
设置为App.IndexController
,您将获得以下工作:
索引控制器:
App.IndexController = Ember.ArrayController.extend({
itemController: "test",
actions: {
removeSelected: function () {
var selected = this.filterProperty('isSelected', true);
console.log(selected);
}
}
});
索引.html:
<script type="text/x-handlebars" data-template-name="index">
<button {{action "removeSelected"}}>remove selected</button>
<ul>
{{#each}}
<li>
{{input type="checkbox" checked=isSelected}}
<label>{{title}}</label>
</li>
{{/each}}
</ul>
</script>
这是这个工作 http://jsfiddle.net/marciojunior/BKUyk/的更新小提琴
相关文章:
- 删除ng模型中的ng模型输入值
- 如何从Backbone.Collection中删除模型
- 如何选择性地从主干集合和服务器中删除模型
- 骨干.js - 从推文中删除模型时出现奇怪的问题
- UI Select在删除后不会更新模型
- 在AngularJS模型中添加/删除标记
- 模型没有'在Emberjs中删除记录后不会更新
- 删除Alfresco自定义模型中的特性值
- 我应该如何从 json 的所有级别(模型、数组)中删除“id”键
- 你如何从猫鼬中删除模型
- Ember.js并选择多个模型进行删除
- JSON 解析或删除数据中的双引号,获取表单模型或 rails 中的数据库
- 主干模型.未设置不删除属性
- 保存或删除集合中的模型时,主干视图不会更新
- Backbone.View:删除与不同模型相关的不同视图
- 从主干.js模型中删除属性
- 角度清单模型取消选中也会删除日期
- BackBoneJs不会将模型删除/更新到服务器
- Angular2-NgFor内部树模型:删除然后添加元素时顺序错误
- 主干模型删除未定义属性