1
我剛開始使用Ember和Ember Data。我有一個非常簡單的服務,它打到我的後端服務(用Node編寫)。我的服務返回兩個項目。在我的HTML中,我的兩個項目顯示,或者至少是他們的ID。其他屬性不呈現。使用Ember數據,但模型上的屬性未呈現
結果:
* Hello, 1 !
* Hello, 2 !
app.js
var App = Ember.Application.create();
App.Store = DS.Store.extend({
revision: 11
});
App.Grunt = DS.Model.extend({
firstName: DS.attr('string'),
lastName: DS.attr('string')
});
App.Router.map(function() {
this.route("grunts", { path: "/grunts" });
});
App.IndexRoute = Ember.Route.extend({
redirect: function() {
this.transitionTo('grunts');
}
});
App.GruntsRoute = Ember.Route.extend({
model: function() {
return App.Grunt.find();
}
});
的index.html
<script type="text/x-handlebars" data-template-name="application">
<div>
<p>{{outlet}}</p>
</div>
</script>
<script type="text/x-handlebars" data-template-name="grunts">
<ul>
{{#each controller}}
<li>Hello, {{id}} {{firstName}} {{lastName}}!</li>
{{/each}}
</ul>
</script>
JSON:
{
"grunts": [
{
"id": 1,
"firstName": "Joe",
"lastName": "Bloggs"
},
{
"id": 2,
"firstName": "Someone",
"lastName": "Else"
}
]
}
感謝您的幫助!