EmberJS:更改加载模型的网址(ember-data) [英] EmberJS: change url for loading model (ember-data)

查看:112
本文介绍了EmberJS:更改加载模型的网址(ember-data)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有ember-data的问题。例如,我在 http:// localhost /〜me / test



中创建了一个项目在我的项目中,我创建了一个存储和模型如下:

  ... init东西在这里... 

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,
});

现在,当我搜索(在我的路线的某个地方)为这样的人

  var person = App.Person.find(params); 

http:// localhost / persons?post_id = 10 被称为。这当然不存在。我会期望像 http:// localhost /〜me / test / persons?post_id = 10

解决方案

这是Ember Data Beta 3



要处理前缀,可以使用命名空间属性 DS.RESTAdapter 。要处理后缀,您将需要使用 c \\ c> c \\ c \\ c> c \\ c \\ c \\ c \\ c \\ c \\ c \\ c中定制 buildURL c $ c> _super()获取原始功能并进行修改。它应该看起来像这样:

  App.ApplicationAdapter = DS.RESTAdapter.extend({
namespace:'〜我/ test',
buildURL:function(){
var normalURL = this._super.apply(this,arguments);
return normalURL +'.php';
}
});


I have problems with ember-data. For example, I've created a project at http://localhost/~me/test

In my project I've created a store and a model as follows:

... 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,
});

Now when I search (somewhere in my route) for a person like this

var person = App.Person.find(params);

The http://localhost/persons?post_id=10 is called. This one does not exist of course. I would've expected something like http://localhost/~me/test/persons?post_id=10. Even better would be http://localhost/~me/test/persons.php?post_id=10 How can I change this url ?

解决方案

This is as of Ember Data Beta 3

To take care of the prefix, you can use the namespace property of DS.RESTAdapter. To take care of the suffix, you'll want to customize the buildURL method of DS.RESTAdapter, using _super() to get the original functionality and modifying that. It should look something like this:

App.ApplicationAdapter = DS.RESTAdapter.extend({
    namespace: '~me/test',
    buildURL: function() {
        var normalURL = this._super.apply(this, arguments);
        return normalURL + '.php';
    }
});

这篇关于EmberJS:更改加载模型的网址(ember-data)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆