alekseykulikov / backbone-offline

[Deprecated] Allows your Backbone.js app to work offline
MIT License
720 stars 56 forks source link

Object #<Object> has no method 'parse' #25

Closed cslarson closed 11 years ago

cslarson commented 11 years ago

I'm getting this error and unsure what I've setup incorrectly. The new model gets saved in localStorage but the error then occurs, I think, when backbone_offline.js calls (line 27):

return options.success((_ref = resp.attributes) != null ? _ref : resp)

which in turn calls (line 454 of backbone.js)

options.success = function(model, resp, options) {...

My page:

<!DOCTYPE html>
<html>
    <head>
        <title>Test</title>
        <script src="lib/mvc/foss/jquery/jquery-1.8.3-min.js"></script>
        <script src="lib/mvc/foss/underscore/underscore.js"></script>
        <script src="lib/mvc/foss/backbone/backbone.js"></script>
        <script src="lib/backbone_offline.js"></script>
<script>

var MealModel = Backbone.Model.extend({
    defaults: {
        name: "A New Meal"
    }
});

var MealsCollection = Backbone.Collection.extend({
    model: MealModel,
    url: "/meals",

    initialize: function(){
        this.storage = new Offline.Storage("meals", this);
    }
});

var meals = new MealsCollection();

meals.create({name: "Risotto"})

</script>
    </head>
    <body>
    </body>
</html>
cslarson commented 11 years ago

Ok, looks like I was using a modified version of Backbone.js.

alekseykulikov commented 11 years ago

;)

cslarson commented 11 years ago

Hi, on further inspection the version of Backbone.js I had been getting the error with was from using backbone.js the github repo master branch. Looks like the way options.success is called has changed. I saw this problem while using backbone.localStorage.js too.

mbhnyc commented 11 years ago

So what's the new way to accomplish this? Running into the same issue, but having trouble grokking the solution from the source!