Jea*_*eri 10 url http-status-code-404 ember.js ember-data
我有使用ember-data的问题.例如,我在http:// localhost/~me/test创建了一个项目
在我的项目中,我创建了一个商店和模型,如下所示:
... init stuff here ...
var attr = DS.attr;
App.Person = DS.Model.extend({
firstName: attr('string'),
lastName: attr('string'),
});
App.Store = DS.Store.extend({
revision: 11,
adapter: DS.RESTAdapter,
});
Run Code Online (Sandbox Code Playgroud)
现在当我搜索(在我的路线的某个地方)这样的人
var person = App.Person.find(params);
Run Code Online (Sandbox Code Playgroud)
该HTTP://本地主机/人POST_ID = 10?被调用.这个当然不存在.我会期待像http:// localhost/~me/test/persons?post_id = 10这样的东西.更好的是 http://localhost/~me/test/persons.php?post_id = 10如何更改此网址?
要处理前缀,您可以使用namespace属性DS.RESTAdapter.要处理后缀,您需要自定义buildURL方法DS.RESTAdapter,使用它_super()来获取原始功能并进行修改.它应该看起来像这样:
App.ApplicationAdapter = DS.RESTAdapter.extend({
namespace: '~me/test',
buildURL: function() {
var normalURL = this._super.apply(this, arguments);
return normalURL + '.php';
}
});
Run Code Online (Sandbox Code Playgroud)
MilkyWayJoe是正确的,在您的适配器中,您可以定义命名空间.
App.Adapter = DS.RESTAdapter.extend({
namespace: '~/me/test'
});
Run Code Online (Sandbox Code Playgroud)