Skip to content

Unable to get property 'collection' of undefined or null reference when calling sync(); #224

@Liero

Description

@Liero

when I call myModel.sync(), I'm getting

Unable to get property 'collection' of undefined or null reference

import { Model } from 'backbone';
import { LocalStorage } from 'backbone.localstorage';

class UserModel extends Model {
    constructor() {
        super();
        this.localStorage = new LocalStorage('api/Account');
    }
    url() {  return "/api/Account"   }
    sync(){
        return super.sync();
    }
    fetch() {
        return super.fetch({
            crossDomain: true, 
            xhrFields: {
                withCredentials: true
            },
            ajaxSync: true,            
        });
    }
    save() {
        return super.save({}, { ajaxSync: false });
    }
}

My scenario is, that I have a readonly REST Resource api/Account that returns info about current user. I want to support offline scenarios. I thought I can call synch at the app startup and it would load info about current user and store it in localstorage

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions