Backbone.js sync:必须指定“url”属性或函数

时间:2014-02-20 00:11:22

标签: backbone.js backbone-collections

关于同样的错误有很多问题,但这个错误是不同的,而且很奇怪。

以下是产生错误的代码:

console.log(this.sources.url);
this.sources.sync({
    success: function (collection, response, options) {
        App.debug('Synchronized media sources.');
    },
    error: function (collection, response, options) {
        App.debug('Unable to synchronize media sources.')
        App.debug(response);
    }
});

this.sources是一个集合。输出是:

/api/sources
routes.js:40 Uncaught Error: A "url" property or function must be specified

所以指定了一个网址。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

Sync需要一个方法('create','read','update'...)通过省略一个方法,你可能会混淆参数。

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


  Backbone.sync = function(method, model, options) {
...

它想要像

这样的东西
this.sources.sync('create',{
    success: function (collection, response, options) {
        App.debug('Synchronized media sources.');
    },
    error: function (collection, response, options) {
        App.debug('Unable to synchronize media sources.')
        App.debug(response);
    }
});
相关问题