我JSON
在这个 URL 的服务器上得到了这种格式的localhost:8080/contractlines
:
{contractlines:[{"id":1,"site":"A","product":"B","price":200}]}
以下是我的 JS 代码:
window.App=Ember.Application.create({
LOG_TRANSITIONS: true
});
App.IndexRoute = Ember.Route.extend({
setupController: function(controller) {
console.log('hello');
// Set the IndexController's `title`
controller.set('title', "My App");
}
});
App.Store = DS.Store.extend({
revision: 12
});
App.Router.map(function() {
this.resource('contractlines');
});
App.Contractline=DS.Model.extend({
id: DS.attr('number'),
site: DS.attr('string'),
product: DS.attr('string'),
price:DS.attr('number')
});
App.ContractlinesRoute=Ember.Route.extend({
model:function(){
var tr=App.Contractline.find();
console.log(tr);
return tr;
}
});
App.ContractlineController = Ember.ArrayController.extend();
以下是我的 HTML 代码:
<script type="text/x-handlebars">
<h1>contractlines</h1>
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="contractlines">
{{#each contractline in controller}}
<ul class="thumbnails">
<li>
{{#linkTo contractlines.contractline contractlines}}
{{contractline.site}}
{{/linkTo}}
</li>
{{/each}}
</ul>
{{outlet}}
</script>
localhost:8080/webapp/testember.html#/contractlines
但是,尽管没有错误,但在我访问时没有生成输出。我成功地JSON
从服务器获取数据。