0

モデルをサーバーと同期しようとしています。残念ながら、モデルを設定urlしても、 url プロパティが指定されていませんrootUrl

言うまでもなく、このモデルで問題なく (GET) 実行できますが、POST を実行しようとすると、突然URLmodel.fetch()が失われます。

>>> 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 に答える