Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

model list save to local not working #111

Open
amelon opened this issue Jan 3, 2012 · 0 comments
Open

model list save to local not working #111

amelon opened this issue Jan 3, 2012 · 0 comments

Comments

@amelon
Copy link

amelon commented Jan 3, 2012

Hi,
firstly, I wish you a good year and hope great fun and nice stuff with javascriptmvc project.

I've tried to use model/list/local and it doesn't work.
store function should use $.toJSON

    store : function(name){
        //  go through and listen to instance updating
        var ids = [], days = this.days;
        this.each(function(i, inst){
            window.localStorage[inst.identity()] = $.toJSON(instance.attrs());
            ids.push(inst.identity());
        });
        window.localStorage[name] = $.toJSON({
            type: this[0] && this[0].constructor.fullName,
            ids: ids
        });
        return this;
    }

At the opposite, retrieve should be something like this:

    retrieve : function(name) {
        // each also needs what they are referencd by ?
        var props,
            instances = [],
            Class;

    if (window.localStorage[name]) {
      props = $.evalJSON(window.localStorage[ name ]);
    }

    props = props || {type : null, ids : []};
    Class = props.type ? $.String.getObject(props.type) :  null;


        for ( var i = 0; i < props.ids.length; i++) {
            var identity = props.ids[i],
                instanceData = $.evalJSON(window.localStorage[ identity ]);
            instances.push( new Class(instanceData) )
        }
        this.push.apply(this,instances);
        return this;
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant