0

在骨干网中,如何将我的实体指向外部端点?

例如,我的应用程序在http://myapp.com上运行

我希望它使用 followgin rest web 服务

http://external.com/api/rest/xxxx

我尝试使用urlRoot属性,但它似乎不起作用

Sagan.FeatureModel = Backbone.Model.extend({
  defaults: {
    name: "New Feature",
    parent: "",
    enabled: false
  },
  urlRoot: 'http://localhost:9001/',
  url: 'features'
});

出于测试目的,该应用程序托管在 localhost:9000 上,外部 Web 服务托管在 localhost:9001 上。

骨干似乎仍然指向 localhost:9000 而不是 9001

4

1 回答 1

3

在您的示例中,您正在为模型设置自定义urlRooturl属性。

设置自定义url属性将使您的自定义urlRoot被忽略,因为此属性用于默认 url行为,请查看Model.url 文档

如果您希望您的模型使用端点 http://external.com/api/rest/features,只需将其添加到urlRoot并保持url不变:

urlRoot: "http://external.com/api/rest/features"

它将创建如下路线:

GET http://external.com/api/rest/features/1

用于获取 id 为 1 的模型。

于 2012-05-23T13:28:56.853 回答