0

我正在尝试将模型与服务器同步。不幸的是,尽管在模型上设置urlrootUrl,我仍然得到url property is not specified

不用说我可以model.fetch()用这个模型做(GET)就好了,但是当我尝试 POST 时,我突然失去了URL

>>> model = window.mod
ClientSchema { cid="c2", attributes={...}, _changing=false, more...}
>>> model.url
"http://localhost:8080/mp/add"
>>> model.urlRoot
"http://localhost:8080/mp/add"
>>> model.set({test:2})
ClientSchema { cid="c2", attributes={...}, _changing=false, more...}
>>> model.sync()
Error: A "url" property or function must be specified
urlError()vendor.js 
Backbone.sync()vendor.js 
.sync()vendor.js 
throw new Error('A "url" property or function must be specified');

模型

# coffeescript
# Chaplin.Model just extends Backbone.Model
module.exports = class ClientSchema extends Chaplin.Model
    url: 'http://localhost:8080/mp/add'
    urlRoot:'http://localhost:8080/mp/add'

模型同步

>>> model.sync.toString()

"function () {
      return Backbone.sync.apply(this, arguments);
    }"    
4

1 回答 1

2

如果您没有覆盖默认同步方法。您将需要传递模型或 url。

这是原始同步:

Backbone.sync = function(method, model, options) {
...
  if (!options.url) {
    params.url = _.result(model, 'url') || urlError();
  }
...
}

当你调用 model.sync() 你没有传递任何东西。

于 2013-11-25T15:56:12.290 回答