【发布时间】:2014-12-23 08:02:31
【问题描述】:
我正在尝试解决我的第一个 Ember.js 应用程序,并且正在努力弄清楚如何获取基于样板/教程的代码并将其传递到我的 Flask 后端。
我想根据邮政编码提供本地事件,邮政编码被传递到后端。
我在选择完全转换 (http://emberjs.com/guides/routing/query-params/#toc_opting-into-a-full-transition) 上看到此页面,现在看到的是参数名称,但看不到通过 API 请求传递的值。
我在浏览器中访问此 URL:http://localhost:5000/?zip=21210
我得到:
127.0.0.1 - - [22/Dec/2014 23:20:51] "GET /?zip=21210 HTTP/1.1" 200 - # first call to load page
127.0.0.1 - - [22/Dec/2014 23:20:52] "GET /api/v1/events?zip= HTTP/1.1" 200 - # call to API
我的 app.js 文件:
App = Ember.Application.create();
App.Router.map(function() {
location: 'auto'
// put your routes here
//this.resource('events', {path: '/'})
});
//var attr = DS.attr;
DS.RESTAdapter.reopen({
namespace: 'api/v1'
});
App.Event = DS.Model.extend({
name: DS.attr('string'),
address: DS.attr('string')
});
App.IndexRoute = Ember.Route.extend({
queryParams: {
zip: {
refreshModel: true
}
},
model: function(params) {
return this.store.findQuery('event', params);
}
});
App.IndexController = Ember.ArrayController.extend({
queryParams: ['zip'],
zip: null
});
【问题讨论】:
-
如果您将
params记录在模型挂钩中,您会得到什么?看起来像zip出于某种原因它即将出现空值。 -
确实为空:app.js:28 Object {zip: null}
标签: ember.js ember-data