骨干localStorage不使用良好的同步方法

我疯了,我的问题!

我有一个模型,我想使用localStorage,但是当我在我的视图中调用model.fetch,我得到错误“错误:一个”url“属性或函数必须指定”。

这个错误是“正常的”,如果我不使用localStorage,因为我没有定义的url属性。 这里的fetch调用应该使用Backbone.sync(也就是localStorage模块的Backbone.localSync覆盖吧?)。

但它永远不会进入localStoragefunction! 就好像模块从未加载过一样。 但我添加了一些console.log无处不在和backbone.localstorage加载并正确初始化。

这就像骨干重新加载的地方,我松散覆盖Backbone.sync指向localStorage.localSync …

错误发生在modules / config.js,render函数中。

这是我的代码:

models / configuration.js':

var Backbone = require('Backbone'); Backbone.LocalStorage = require('Backbone.LocalStorage'); // Exports the module module.exports = Backbone.Model.extend({ defaults:{ id: 1 agencyName : 'xxx', agencyId : 'xxx', serviceUrl : 'xxx' }, localStorage: new Backbone.LocalStorage('Configuration') }); 

data / configuration.js:

 'use strict'; // Get class dependencies var Config = require('../models/configuration'); // export module module.exports = new Config(); 

controller / config.js:

 'use strict'; // Gets the controller dependencies var region = require('../regions/main'), dispatcher = require('../services/dispatcher'), ConfigView = require('../modules/config'), config = require('../data/configuration'); // manages the route for the home page module.exports = function() { dispatcher.command('header:set', [ 'Configuration', false, true]); region.show(new ConfigView({model: config})); }; 

modules / config.js:

 'use strict'; // Adds the requires for the module var Backbone = require('Backbone'); // Exports the header module module.exports = Backbone.View.extend({ // Sets the template tpl: require('../templates/config.tpl'), // Sets the class for the Module className: 'home module', // Sets the event for the menu module events: { 'mouseup': 'onScreenTap' }, // Fired when the user clicks anywhere in the menu, to close it onScreenTap: function(e) { e.preventDefault(); // if a menu item was clicked, it navigates to the module var node = e.target; if (node.classList.contains('btn')) { this.model.save(); } }, // Initializes the module initialize: function () { }, // Renders the view render: function () { this.model.fetch(); this.$el.html(this.tpl({ config: this.model })); return this; } }); 

好的,我发现这个问题! 我到处都在使用“require(”Backbone“)”,但是在backbone.localStorage.js中,主干需要“require(”backbone“)”! 所以2个Backbone的实例被caching了,我没有使用这个好的。

希望这将有助于某一天..