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"
}
]
}
感谢您的帮助!