这是我在ember中的第一个应用程序。 我有一个输出此JSON的API网址:
{"search":{"id":"123","idate":"2016-11-20","fdate":"2016-11-25","keywords":["cuccioli","gattini","rocco"]}}
应用结构:
应用程序/适配器/ application.js中
import DS from 'ember-data';
export default DS.RESTAdapter.extend({
namespace: 'v1',
host: 'http://myhost'
});
应用程序/模型/ search.js
import DS from 'ember-data';
export default DS.Model.extend({
idate: DS.attr('date'),
fdate: DS.attr('date'),
keywords: DS.attr()
});
应用程序/路由/ search.js
import Ember from 'ember';
export default Ember.Route.extend({
model() {
// this not work
return this.get('store').findRecord('search', 123);
// this work
/*return this.get('store').createRecord('search', {
"id": "456",
"idate": "2016-11-24",
"fdate": "2016-12-01",
"keywords": ["ssss", "mmmm"]
}
);*/
}
});
应用程序/模板/组件/ search.hbs
<h2>Search page</h2>
<ul>
{{#each model as |s|}}
<li>id {{s.id}}</li>
<li>idate {{s.idate}}</li>
<li>fdate {{s.fdate}}</li>
<li>keywords {{s.keywords}}</li>
{{/each}}
</ul>
应用程序/ router.js
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: config.locationType,
rootURL: config.rootURL
});
Router.map(function() {
this.route('search');
});
export default Router;
问题是模型在模板中似乎是空的,但在检查员中填充。
提前感谢您的支持。我会感激每一个答案。