backbone.js - How to set/initialize collection from it's model -


i'm trying build application on backbone.js uses html5 localstorage store , retrieve data. instead of retrieving data localstorage, method getlocalstoragedata on model return localstorage data.

now problem here, i'm unable initialize/set collection model's method.

any highly appreciated. thanks.

router:

(collection shared across 2 routes).

    var workspace = backbone.router.extend({         routes: {             'dashboard': 'dashboard',             'newsearch': 'newsearch'         },         collection: new mmm.common.collection.studycollection(),         dashboard: function () {             $("#newsearch").css('display', 'none');             $("#dvdashboard").css('display', 'block');              activestudylistview = new mmm.dashboard.view.activestudylistview({                 collection: this.collection             });         },         newsearch: function () {             $("#dvdashboard").css('display', 'none');             $("#newsearch").css('display', 'block');              studyview = new mmm.newsearch.view.study({                 collection: this.collection             });          }     }); 

model:

mmm.common.allstudies = [     {study_index : 1, study_name : 'sample test', status : 'active' },     {study_index : 2, study_name : 'abc test', status : 'active' },     {study_index : 3, study_name : 'new study', status : 'active' } ];  mmm.common.model.studymodel = backbone.model.extend({     defaults : {         'status' : 'active'     },     getlocalstoragedata : function() {         return mmm.common.allstudies;     } }); 

collection:

mmm.common.collection.studycollection = backbone.collection.extend({     model : mmm.common.model.studymodel }); 


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -