Ember-Data:Restful Put

时间:2013-12-10 13:57:02

标签: javascript ember.js ember-data

我正在尝试做一个简单的restful put命令。我的问题是我需要将put命令放到我的商店的另一个终点。

我有我的休息适配器

    DS.RESTAdapter.reopen({
    namespace: 'datastore'
});

我需要能够调用终点,但不知道该怎么做;

类似的东西,

store('foundItems', JSON)

其中foundItems是终点。

1 个答案:

答案 0 :(得分:0)

你想创建一个自定义RESTAdapter并覆盖buildURL,这应该可以帮助你开始

App.PeopleAdapter = DS.RESTAdapter.extend({
  host: 'http://www.google.com',
  namespace: 'api/v1',

/**
Builds a URL for a given type and optional ID.

By default, it pluralizes the type's name (for example,
'post' becomes 'posts' and 'person' becomes 'people').

If an ID is specified, it adds the ID to the path generated
for the type, separated by a `/`.

@method buildURL
@param {String} type
@param {String} id
@returns String
*/
buildURL: function(type, id) {
 var url = [],
     host = get(this, 'host'),
     prefix = this.urlPrefix();

 if (type) { url.push(this.pathForType(type)); }
 if (id) { url.push(id); }

 if (prefix) { url.unshift(prefix); }

 url = url.join('/');
 if (!host && url) { url = '/' + url; }

 return url;
},

});
相关问题