I'm wondering/guessing that there is something that I'm doing wrong, but I currently cannot get Backbone-nested to correctly .set using dot or bracket notation. In fact, it only seems to work if I use JSON formatting data. (am using Backbone 1.0, btw)
UPDATE: Actually, using the master version backbone-nested I can't get any method to properly .set or .add. What I outline as working below only works with backbone-nested v1.12
var schema = '{"pane_id":15,"title":"job boards","rows":{"0":{"dataHeight":50,"dataId":1,"CSSid":"pane-row-1","CSSclass":"pane-row show-grid row-height50","columns":{"0":{"dataId":1,"CSSclass":"row-height100 pane-column span","style":"width: 675px;","CSSid":"pane-column-1","formValues":{"inputUrl":"http://groups.drupal.org/jobs?group_nid=All&keys=&field_type_value_many_to_one=All&field_telecommute_value_many_to_one=1","inputSelector":"#content .view-content","requireLogin":false,"inputFormId":"","unameField":"","passField":"","inputUname":"","inputPassword":""},"pixelWidth":675,"percentWidth":46,"newWidth":673},"1":{"dataId":7,"CSSclass":"row-height100 pane-column span","style":"width: 789px;","CSSid":"pane-column-7","formValues":{"inputUrl":"http://jobsearch.monster.com/search/?q=drupal","inputSelector":"#primaryResults","requireLogin":false,"inputFormId":"","unameField":"","passField":"","inputUname":"","inputPassword":""},"pixelWidth":789,"percentWidth":54,"newWidth":791},"length":2}},"1":{"dataHeight":50,"dataId":6,"CSSid":"pane-row-6","CSSclass":"pane-row show-grid row-height50","columns":{"0":{"dataId":6,"CSSclass":"row-height100 pane-column span","style":"width: 673px;","CSSid":"pane-column-6","formValues":{"inputUrl":"http://hackerlab.jobboard.io/","inputSelector":".job-listings","requireLogin":false,"inputFormId":"","unameField":"","passField":"","inputUname":"","inputPassword":""},"pixelWidth":673,"percentWidth":46,"newWidth":673},"1":{"dataId":11,"CSSclass":"row-height100 pane-column span","style":"width: 791px;","CSSid":"pane-column-11","formValues":{"inputUrl":"http://www.engineerjobs.com/jobs/software-engineering/javascript/california/sacramento.php","inputSelector":"#jobs_table_s","requireLogin":false,"inputFormId":"","unameField":"","passField":"","inputUname":"","inputPassword":""},"pixelWidth":791,"percentWidth":54,"newWidth":791},"length":2}}}}';
var nonJSON = $.parseJSON(schema);
var singleLayout = new Backbone.NestedModel ({
"jobboard" : nonJSON
});
// this works and does not destroy the object
singleLayout.set({"jobboard.first" : "Bob"});
// None of the four following attempts work. They all result in a destroyed object
//singleLayout.set({'jobboard.rows[0].columns[0].smurf': 'zap'});
//singleLayout.set({'jobboard.rows.0.columns.0.smurf': 'zap'});
//singleLayout.add('jobboard.rows.0.columns.0', { "smurf" : 'zap'});
// this is the only method I can get to work for deep nesting
singleLayout.set({
"jobboard": {
"rows": {
"0": {
"columns": {
"0": {"smurf": "Zap" }
}
}
}
}
});
console.dir(singleLayout);
I'm wondering/guessing that there is something that I'm doing wrong, but I currently cannot get Backbone-nested to correctly .set using dot or bracket notation. In fact, it only seems to work if I use JSON formatting data. (am using Backbone 1.0, btw)
UPDATE: Actually, using the master version backbone-nested I can't get any method to properly .set or .add. What I outline as working below only works with backbone-nested v1.12
Any suggestions/corrections appreciated. Thanks!