jupiterjs/jquerymx — Issue #111: model list save to local not working
Author: amelon
Created: 2012-01-03 11:44:37+00:00
State: open

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

```javascript
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:

```javascript
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;
}
```