Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backbone.LocalStorage is not a function

I am using backbone localstorage plugin however, it is giving me following error.

Uncaught TypeError: Backbone.LocalStorage is not a function

I am using it in following way in my collection

var TodoList = Backbone.Collection.extend({
    model: TodoModel,
    localStorage: new Backbone.LocalStorage('todos-backbone')
});

How can I solve this problem?

UPDATE

I import them in index.html

<script src="node_modules/jquery/dist/jquery.min.js"></script>
<script src="node_modules/backbone/node_modules/underscore/underscore-min.js"></script>
<script src="node_modules/backbone/backbone-min.js"></script>
<script src="node_modules/backbone-localstorage/backbone-localStorage.js"></script>
<script src="js/models/todo.js"></script>
<script src="js/collections/todos.js"></script>
<script src="js/views/todos.js"></script>
<script src="js/views/app.js"></script>
<!-- <script src="js/routers/router.js"></script> -->
<script src="js/app.js"></script>
like image 929
Om3ga Avatar asked Apr 01 '26 16:04

Om3ga


1 Answers

I think you are confusing https://github.com/jeromegn/Backbone.localStorage and https://github.com/robmoorman/backbone-localstorage. Backbone.LocalStorage is a function only in the former while the one you have included is used like this:

var TodoList = Backbone.Collection.extend({
    model: TodoModel,
    localStorage: true
});
like image 57
ekuusela Avatar answered Apr 03 '26 04:04

ekuusela



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!