을 삭제하기위한 여러 모델을 선택 :Ember.js 그리고 난 다음 발견했습니다 ember.js 문서에서
컨트롤러는 디스플레이 로직 모델을 장식 할 수 있습니다. 일반적으로 모델에는 서버에 저장된 속성이 있고 컨트롤러에는 서버에 저장할 필요가없는 속성이 있습니다.
"선택"기능을 응용 프로그램에 추가하려고합니다.
여기 jsfiddle이다 http://jsfiddle.net/JWf7X/
합니다 (CONSOLE.LOG 비어 있기 때문에) 그 필터 특성이없는 컨트롤러 모델별로 필터링되어 보인다.
this.filterProperty('isSelected', true); //managing models
어떻게하면 removeSelected 작업을 올바르게 작성할 수 있습니까?
"isSelected"를 컨트롤러에 저장하는 올바른 방법은 무엇입니까? 이 속성은 REST API를 통해 서버에서로드되지 않으므로 모델에 isSelected를 추가하는 것이 올바른 방법이 아니므로 저장하지 않는 것이 좋습니다.
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 for help. 실수로 각 도우미에서 itemController를 설정하면 IndexController에 대해 itemController가 설정됩니다. –
당신은 오신 것을 환영합니다. 단지 내 대답에'각 itemController = "test"'단지'each' 업데이트가 필요하지 않습니다. 바이올린이 맞습니다. –