-
24 Mar 2012 11:31 AM #1
Unanswered: Destroy temporary store/view?
Unanswered: Destroy temporary store/view?
So I've become so frustrated by Sencha's data methods that I'm finding I need to populate my stores with regular ajax calls instead of Sencha methods. But that leads me to a problem - I'm creating a ton of stores that just sit around.
In old-timey iOS, I would've called a personStore.release or something at the end of that function, to let the app know to destroy the store if nobody else was using it. But in Sencha if I destroy it now, the list loses its data - but if I don't, I lose the reference to the store since it's a local variable...Code:onPeopleShow: function(view){ var personStore = Ext.create('SMToolkit.store.Persons'); var list = this.getPeople(); $.getJSON("index.php/api/persons",function(data){ $.each(data, function(k,v){ personStore.add(v); }); list.setStore(personStore); list.refresh(); }); $.getJSON('index.php/api/rolespersons/'+window.currentRole.data.id, function(data){ $.each(data, function(k,v){ }); }); },
-
25 Mar 2012 5:24 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,582
- Vote Rating
- 433
- Answers
- 3101
Why aren't you able to let the store do the loading?
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
25 Mar 2012 8:45 AM #3
The Sencha stores just don't seem to work. I spent the better part of two weeks trying to use them, but they choked on the associations and didn't refresh as expected, so out of desperation I went back to jquery.
-
25 Mar 2012 8:54 AM #4Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,582
- Vote Rating
- 433
- Answers
- 3101
If you give me a sample response I'm sure I can create a store to read it.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
25 Mar 2012 9:58 AM #5
Sure!

Here's a LIST from the rest store for Roles:
Roles are associated to Persons many-to-many (here's a result from Persons):Code:[{"id":"25378","name":"Francisco","description":null,"type":null,"show_id":"2354","user_id":"5"},{"id":"25379","name":"Bernardo","description":null,"type":null,"show_id":"2354","user_id":"5"},{"id":"25380","name":"Marcellus","description":null,"type":null,"show_id":"2354","user_id":"5"},{"id":"25381","name":"Horatio","description":null,"type":null,"show_id":"2354","user_id":"5"},{"id":"25382","name":"Claudius","description":null,"type":null,"show_id":"2354","user_id":"5"},{"id":"25383","name":"Voltimand","description":null,"type":null,"show_id":"2354","user_id":"5"},{"id":"25384","name":"Laertes","description":null,"type":null,"show_id":"2354","user_id":"5"},{"id":"25385","name":"Polonius","description":null,"type":null,"show_id":"2354","user_id":"5"},{"id":"25386","name":"Hamlet","description":null,"type":null,"show_id":"2354","user_id":"5"},{"id":"25387","name":"Gertrude","description":null,"type":null,"show_id":"2354","user_id":"5"},{"id":"25388","name":"Ophelia","description":null,"type":null,"show_id":"2354","user_id":"5"},{"id":"25389","name":"Ghost (Voice only)","description":null,"type":null,"show_id":"2354","user_id":"5"},{"id":"25390","name":"Reynaldo","description":null,"type":null,"show_id":"2354","user_id":"5"},{"id":"25391","name":"Rosencrantz","description":null,"type":null,"show_id":"2354","user_id":"5"},{"id":"25392","name":"Guildenstern","description":null,"type":null,"show_id":"2354","user_id":"5"},{"id":"25393","name":"Player King","description":null,"type":null,"show_id":"2354","user_id":"5"},{"id":"25394","name":"Player Queen","description":null,"type":null,"show_id":"2354","user_id":"5"},{"id":"25395","name":"Lucianus","description":null,"type":null,"show_id":"2354","user_id":"5"},{"id":"25396","name":"Fortinbras","description":null,"type":null,"show_id":"2354","user_id":"5"},{"id":"25397","name":"Gravedigger","description":null,"type":null,"show_id":"2354","user_id":"5"},{"id":"25398","name":"Priest","description":null,"type":null,"show_id":"2354","user_id":"5"},{"id":"25399","name":"Osric","description":null,"type":null,"show_id":"2354","user_id":"5"},{"id":"25400","name":"Lady in Waiting","description":null,"type":null,"show_id":"2354","user_id":"5"},{"id":"25401","name":"Attendant","description":null,"type":null,"show_id":"2354","user_id":"5"},{"id":"25402","name":"Ophelia & Gertrude","description":null,"type":null,"show_id":"2354","user_id":"5"},{"id":"25404","name":"Harry","description":"","type":"Lead","show_id":"2354","user_id":"5"}]
there is a personsroles table in the db , it has three columns - person_id, role_id and user_id. the primary key is a composite person_id/role_idCode:[{"id":"3","first_name":"George","last_name":"Washington","email":"","address":"","phone1":"","phone2":"","thumbnail":null,"image":null,"type":"Actor","location":"","user_id":"5"},{"id":"4","first_name":"Martha","last_name":"Washington","email":"","address":"","phone1":"","phone2":"","thumbnail":null,"image":null,"type":"Actor","location":"","user_id":"5"},{"id":"5","first_name":"Thomas","last_name":"Jefferson","email":null,"address":null,"phone1":null,"phone2":null,"thumbnail":null,"image":null,"type":null,"location":null,"user_id":"5"},{"id":"8","first_name":"Walter","last_name":"Cronkite","email":"","address":"","phone1":"","phone2":"","thumbnail":null,"image":null,"type":"Actor","location":"","user_id":"5"},{"id":"9","first_name":"Larry","last_name":"Miller","email":"","address":"","phone1":"","phone2":"","thumbnail":null,"image":null,"type":"Actor","location":"","user_id":"5"},{"id":"10","first_name":"Hank","last_name":"Pym","email":"","address":"","phone1":"","phone2":"","thumbnail":null,"image":null,"type":"Actor","location":"","user_id":"5"}]
I used to have models like this:
Code:Ext.define('SMToolkit.model.Person', { extend: 'Ext.data.Model', config: { fields: [ 'id', 'first_name', 'last_name', 'email', 'address', 'phone1', 'phone2', 'type', 'location' ], hasMany: [ { model: 'SMToolkit.model.Person_Role_Rest', name: 'role' } ], proxy: { type: 'rest', url : 'index.php/api/persons' } } and Ext.define('SMToolkit.model.Role', { extend: 'Ext.data.Model', config: { fields: [ 'id', 'name', 'description', 'type', 'show_id' - ], - hasMany: [ - { - model: 'SMToolkit.model.Person_Role_Rest', - name: 'person' - }, - { - model: 'SMToolkit.model.Scene_Role_Rest', - name: 'scene' - }, - { - model: 'SMToolkit.model.Thing', - name: 'thing' - } - ], - proxy: { - type: 'rest', - url : 'index.php/api/roles' - } - } });
-
26 Mar 2012 5:02 AM #6Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,582
- Vote Rating
- 433
- Answers
- 3101
Here are my two models that I used to show how to get it to work:
Here are the stores for my test:Code:Ext.define('City', { extend : 'Ext.data.Model', config : { fields : [ { name : 'id', type : 'int' }, 'name', 'description', 'type', { name : 'show_id', type : 'int' }, { name : 'user_id', type : 'int' } ], proxy : { type : 'ajax', url : 'data/json.json', reader : 'json' }, hasMany : { model : 'Person', name : 'persons', foreignKey : 'user_id', primaryKey : 'user_id', autoLoad : true } } }); Ext.define('Person', { extend : 'Ext.data.Model', config : { fields : [ { name : 'id', type : 'int' }, 'first_name', 'last_name', 'email', 'address', 'phone1', 'phone2', 'thumbnail', 'image', 'type', 'location', { name : 'user_id', type : 'int' } ], proxy : { type : 'ajax', url : 'data/json2.json', reader : 'json' }, hasMany : { model : 'City', name : 'cities', foreignKey : 'user_id', primaryKey : 'user_id', autoLoad : true } } });
json.json has the first JSON you provided, json2.json has the second JSON.Code:new Ext.data.Store({ model : 'City', autoLoad : true, listeners : { load : function(store) { var rec = store.getAt(0), persons = rec.persons(); persons.on('load', function(personsStore) { console.log(personsStore.getCount() + ' Persons in this city'); }); } } }); new Ext.data.Store({ model : 'Person', autoLoad : true, listeners : { load : function(store) { var rec = store.getAt(0), cities = rec.cities(); cities.on('load', function(citiesStore) { console.log(citiesStore.getCount() + ' Cities for this person'); }); } } });Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.


Reply With Quote