试图解释您的“调整模型”,计算属性(http://emberjs.com/guides/object-model/computed-properties/)可能是您正在寻找的。
例子:
假设像这样的 JSON
{
"albums": [
{
"id": 1,
"artist":"Pearl Jam",
"title":"Jeremy",
"genre":"Indipendent"
},
{
"id": 2,
"artist":"Soundgarden",
"title":"Superunknown",
"genre":"Indipendent"
}
]
}
你的模型可能是
App.Album = DS.Model.extend({
artist: DS.attr('string'),
title: DS.attr('string'),
genre: DS.attr('string'),
quickInfo: function(){
var artist = this.get('artist');
var title = this.get('title');
var genre = this.get('genre');
return "This album is from " + artist + ", it's called " + title + " and is of genre " + genre;
}.property('artist', 'title', 'genre');
});
然后在你的车把里
...
{{#each album in model}}
<li>{{ album.quickInfo }}</li>
{{/each}}
...
html输出
This album is from Pearl Jam, it's called Jeremy and is of genre Indipendent
...
这就是你说的意思吗
渲染前调整模型
?
希望能帮助到你