ArrayController排序-每条语句-模型
ArrayController sorting - each statement - model
我一直在尝试根据代码学校 ember 教程制作一个新的图书馆应用程序(书籍而不是产品......不太复杂)。
我使用的是最新的 ember.js 稳定版 1.1.10。
在我的模板中使用 {{#each}},
js:
App.BooksRoute = Ember.Route.extend({
model: function () {
return this.store.findAll('book');
}
});
html:
{{#each}}
<h1>{{title}}</h1>
{{/each}}
控制台中显示以下警告
DEPRECATION: Using the context switching form of {{each}} is deprecated. Please use the keyword form (`{{#each foo in bar}}`)
所以我一直在尝试使用推荐的语法,我发现这个很管用
html:
{{#each book in model}}
<h1>{{book.title}}</h1>
{{/each}}
但是当需要尝试 arrayController 中的 sortProperties 时,我的 {{#each在模型中预订}}
js:
App.BooksRoute = Ember.Route.extend({
model: function () {
return this.store.findAll('book');
}
});
App.BooksController = Ember.ArrayController.extend({
sortProperties: ['title']
});
html:
{{#each book in model}}
<h1>{{book.title}}</h1>
{{/each}}
我的书没有分类...
我找到了另一个解决方法,在我的 ArrayController 中构建一个 属性:
js:
App.BooksRoute = Ember.Route.extend({
model: function () {
return this.store.findAll('book');
}
});
App.BooksController = Ember.ArrayController.extend({
books: function(){
return this;
}.property(),
sortProperties: ['title']
});
html:
{{#each book in books}}
<h1>{{book.title}}</h1>
{{/each}}
已排序!
, 但我不满意...
是否有另一种 cleanest/simplest 方法来使用 ember 1.1.10 中定义的 each 语句并对我的数组进行排序?
而不是{{#each book in model}}
使用 {{#each book in arrangedContent}}
或 {{#each book in this}}
尝试使用 'arrangedContent' 在 ArrayController 中对数组进行排序。
App.BooksController = Ember.ArrayController.extend({
sortProperties: ['title'],
content: function() {
return this.get('arrangedContent'); // this gives sorted array
},
});
希望对您有所帮助
我一直在尝试根据代码学校 ember 教程制作一个新的图书馆应用程序(书籍而不是产品......不太复杂)。
我使用的是最新的 ember.js 稳定版 1.1.10。
在我的模板中使用 {{#each}},
js:
App.BooksRoute = Ember.Route.extend({
model: function () {
return this.store.findAll('book');
}
});
html:
{{#each}}
<h1>{{title}}</h1>
{{/each}}
控制台中显示以下警告
DEPRECATION: Using the context switching form of {{each}} is deprecated. Please use the keyword form (`{{#each foo in bar}}`)
所以我一直在尝试使用推荐的语法,我发现这个很管用 html:
{{#each book in model}}
<h1>{{book.title}}</h1>
{{/each}}
但是当需要尝试 arrayController 中的 sortProperties 时,我的 {{#each在模型中预订}}
js:
App.BooksRoute = Ember.Route.extend({
model: function () {
return this.store.findAll('book');
}
});
App.BooksController = Ember.ArrayController.extend({
sortProperties: ['title']
});
html:
{{#each book in model}}
<h1>{{book.title}}</h1>
{{/each}}
我的书没有分类...
我找到了另一个解决方法,在我的 ArrayController 中构建一个 属性:
js:
App.BooksRoute = Ember.Route.extend({
model: function () {
return this.store.findAll('book');
}
});
App.BooksController = Ember.ArrayController.extend({
books: function(){
return this;
}.property(),
sortProperties: ['title']
});
html:
{{#each book in books}}
<h1>{{book.title}}</h1>
{{/each}}
已排序! , 但我不满意...
是否有另一种 cleanest/simplest 方法来使用 ember 1.1.10 中定义的 each 语句并对我的数组进行排序?
而不是{{#each book in model}}
使用 {{#each book in arrangedContent}}
或 {{#each book in this}}
尝试使用 'arrangedContent' 在 ArrayController 中对数组进行排序。
App.BooksController = Ember.ArrayController.extend({
sortProperties: ['title'],
content: function() {
return this.get('arrangedContent'); // this gives sorted array
},
});
希望对您有所帮助