-
31 Jul 2012 4:08 AM #1Sencha Premium Member
- Join Date
- Apr 2012
- Location
- Mumbai, India
- Posts
- 191
- Vote Rating
- -1
- Answers
- 10
Unanswered: Dynamically setting fields[ ] array for List Component
Unanswered: Dynamically setting fields[ ] array for List Component
Hi,
I have a list component, which has a store, model and it's corresponding fields[ ] array.
I am trying to read the data values from a nested json, so I am using custom reader and trying to access data[ ] for store and fieldArray[ ] for fields of model via custom Accessor function.
I have 2 buttons, clicking on each button changes the data of list dynamically ( & of course will change it's fields[ ] as well)
So, basically I need to design a list component for whom data[ ] and fields[ ] will change according to certain actions performed.
Sample Json:-
data[ ] => Actual List Data
fieldArray[ ] => fields for Model of List Store
PS : One thing that I tried was setting fields returned from custom accessor function on load( ) of list store, but list wasn't getting updated. But at console.log( ) I could see the new fields[ ] array being set.Code:{ "success": true, "total": 2, "data": [ { "id": 1, "company": "3m Co", "price": 71.72, "change": 0.02, "pct": 0.03, "updated": "9/1/2012" }, { "id": 2, "company": "Alcoa Inc", "price": 29.01, "change": 0.42, "pct": 1.47, "updated": "9/1/2012" }, ], "fieldArray": [ 'id', 'company', 'price', 'pct', 'updated' ] }
How to achieve this ?
-
31 Jul 2012 4:44 AM #2
-
31 Jul 2012 4:52 AM #3Sencha Premium Member
- Join Date
- Apr 2012
- Location
- Mumbai, India
- Posts
- 191
- Vote Rating
- -1
- Answers
- 10
That doesn't help.
First of all - Can I do like this ? I mean, I am setting new fields[ ] array for list inside list load( ) event.
Is this correct ? If not, what is the alternative ?
-
31 Jul 2012 4:55 AM #4
An alternative would be to use two Models, I think. I've never done what you are explaining here.
-
31 Jul 2012 4:58 AM #5Sencha Premium Member
- Join Date
- Apr 2012
- Location
- Mumbai, India
- Posts
- 191
- Vote Rating
- -1
- Answers
- 10
Ok, but what if I had several sets of data.
According to your answer, I could have then hundred's of different model.
What could be the optimal solution ?
Note : I want to have fields[ ] dynamically set at any cost, I can't hard-code them.
-
31 Jul 2012 5:09 AM #6
You would need to refill the model with the new records, or use the set method, if you change the fields and reload the store. Changing the fields only changes whats available to use for a record, but it doesn't change any of the instances already created.
I don't know any optimal way of doing this. Maybe someone else does.
I found a link that could help, but its all I could find:
http://stackoverflow.com/questions/10789433/extend-ext-data-model-add-fields-dynamically


Reply With Quote