PDA

View Full Version : problem while showing nested data in list..



irfaniqbal
19 Jul 2011, 10:39 AM
hi,
I have an app with MVC structure. i am having a problem while showing data in list. the list showed data correctly when the Store first loaded after Ajax response. but when i display that similar data from already loaded store the nested data does not displayed in the list. Here is the code for my List.


Application.views.SupplementDataList = Ext.extend(Ext.List, {
itemTpl : [
'<tpl for=".">',
'<div class="next"><div>{timing_name}</div></div>',
'<tpl for="supplements">',
'{name}<br>',
'</tpl>',
'</tpl>'
],
store: "SupplementTimes"
}
});

The problem which i have figured out is that the structure of the store is changed when i used already loaded store. i have attached an image to illustrate my problem.
27043
here is another screen shot.
27044
any quick reply is my pleasure. thanks

AndreaCammarata
19 Jul 2011, 10:56 AM
Hey infaniqbal.
From the code you post I don't see anything weird.
I think that your problem could be in your server side response instead of the itemTpl.
Can you show me the screenshot of your first request / response and the second one?

irfaniqbal
19 Jul 2011, 11:04 AM
thanks andrea once again for your quick response. Acutally, there is only one request which i have sent to the server and the response of that request is:


{
"response": {
"On rising": {
"supplements": [
{
"id": "16798",
"uuid": "",
"plan_id": "12716",
"user_supplement_id": "10176",
"supplement_id": "5",
"name": "Multivitamin +Plus Vital Minerals",
"instructions": "",
"unit": "Capsule(s)",
"dosage": "4",
"intake": "0",
"supplement_times": null,
"plan_date": "2011-07-19",
"created": "2011-07-19 15:51:17",
"updated": "2011-07-19 15:51:17",
"created_by": null,
"updated_by": null
},
{
"id": "16799",
"uuid": "",
"plan_id": "12716",
"user_supplement_id": "10177",
"supplement_id": "6",
"name": "Whey Protein",
"instructions": "",
"unit": "Pill(s)",
"dosage": "2",
"intake": "0",
"supplement_times": null,
"plan_date": "2011-07-19",
"created": "2011-07-19 15:51:17",
"updated": "2011-07-19 15:51:17",
"created_by": null,
"updated_by": null
}
],
"time": {
"tracked": "0",
"count": 16,
"reminder": 1,
"reminder_time": "5:00",
"reminder_time_unit": "AM"
},
"timing_name": "On rising",
"id": 8
},
"Morning": {
"supplements": [
{
"id": "16799",
"uuid": "",
"plan_id": "12716",
"user_supplement_id": "10177",
"supplement_id": "6",
"name": "Whey Protein",
"instructions": "",
"unit": "Pill(s)",
"dosage": "2",
"intake": "0",
"supplement_times": null,
"plan_date": "2011-07-19",
"created": "2011-07-19 15:51:17",
"updated": "2011-07-19 15:51:17",
"created_by": null,
"updated_by": null
}
],
"time": {
"tracked": "0",
"count": 16,
"reminder": 1,
"reminder_time": "5:00",
"reminder_time_unit": "AM"
},
"timing_name": "Morning",
"id": 2
},
"Mid day": {
"supplements": [
{
"id": "16800",
"uuid": "",
"plan_id": "12716",
"user_supplement_id": "10178",
"supplement_id": "12",
"name": "Vitamin D spray",
"instructions": "",
"unit": "Drop(s)",
"dosage": "3",
"intake": "0",
"supplement_times": null,
"plan_date": "2011-07-19",
"created": "2011-07-19 15:51:17",
"updated": "2011-07-19 15:51:17",
"created_by": null,
"updated_by": null
}
],
"time": {
"tracked": "0",
"count": 16,
"reminder": 1,
"reminder_time": "5:00",
"reminder_time_unit": "AM"
},
"timing_name": "Mid day",
"id": 3
},
"Afternoon": {
"supplements": [
{
"id": "16800",
"uuid": "",
"plan_id": "12716",
"user_supplement_id": "10178",
"supplement_id": "12",
"name": "Vitamin D spray",
"instructions": "",
"unit": "Drop(s)",
"dosage": "3",
"intake": "0",
"supplement_times": null,
"plan_date": "2011-07-19",
"created": "2011-07-19 15:51:17",
"updated": "2011-07-19 15:51:17",
"created_by": null,
"updated_by": null
}
],
"time": {
"tracked": "0",
"count": 16,
"reminder": 1,
"reminder_time": "5:00",
"reminder_time_unit": "AM"
},
"timing_name": "Afternoon",
"id": 4
},
"Evening": {
"supplements": [
{
"id": "16800",
"uuid": "",
"plan_id": "12716",
"user_supplement_id": "10178",
"supplement_id": "12",
"name": "Vitamin D spray",
"instructions": "",
"unit": "Drop(s)",
"dosage": "3",
"intake": "0",
"supplement_times": null,
"plan_date": "2011-07-19",
"created": "2011-07-19 15:51:17",
"updated": "2011-07-19 15:51:17",
"created_by": null,
"updated_by": null
}
],
"time": {
"tracked": "0",
"count": 16,
"reminder": 1,
"reminder_time": "5:00",
"reminder_time_unit": "AM"
},
"timing_name": "Evening",
"id": 5
},
"Before bed": {
"supplements": [],
"time": {
"tracked": 0,
"count": 0,
"reminder": 0,
"reminder_time": 0,
"reminder_time_unit": ""
},
"timing_name": "Before bed",
"id": 7
}
}
}


and here is the controller action :



get_supplements: function(){
var userID = is_valid_session();
var supplementPanel = Ext.getCmp('SupplementPanelID');
Application.stores.supplements = Ext.getStore('SupplementTimes');
var recLength = Application.stores.supplements.data.items.length;

if(recLength == 0){
loadMask.show();
Ext.Ajax.request({
url: getSupplementsURL+'/'+userID,
success: function(response, opts) {
loadMask.hide();
var obj = Ext.decode(response.responseText);

obj = obj.response;
var supplement_data = [];
var i =0;
for(var ob in obj){
var o = obj[ob];
if(typeof(o) != 'function'){
supplement_data[i] = o;
i++;
}
}
Application.stores.supplements.removeAll();
Application.stores.supplements.add(supplement_data);
console.log(Application.stores.supplements)//1st screenshot contains log from this point
add_item_in_panel(supplementPanel, 'SupplementPanelID', 'supplementDataPanel', 'supplementDataPanelID');
},
failure: function(response, opts) {
loadMask.hide();
Ext.Msg.alert('', 'unable to get supplements, try later.');
return;
}
});
}else{
console.log(Application.stores.supplements)//2nd screenshot contains log from this point
add_item_in_panel(supplementPanel, 'SupplementPanelID', 'supplementDataPanel', 'supplementDataPanelID');
}
}


the IF will executed when i first load the store and in ELSE portion the Store is already loaded. hope it helps. thanks

AndreaCammarata
19 Jul 2011, 11:30 AM
Instead of doing this



Application.stores.supplements.add(supplement_data);
console.log(Application.stores.supplements)//1st screenshot contains log from this point


Try to create a new store model with



var record = Ext.ModelMgr.create(supplement_data, 'STORE_MODEL_NAME');
Application.stores.supplements.add(record);
console.log(Application.stores.supplements)//1st screenshot contains log from this point


Does it change something?

irfaniqbal
19 Jul 2011, 11:43 AM
no andrea it does not change any thing, infact this solution not work at all.

the console of "supplement_data" is here :

27045

and here is the code for my Model:


Application.models.Supplement = Ext.regModel('SupplementTime', {
fields:[
'id', 'timing_name', 'supplements', 'time'
],
proxy: "app_proxy"
});


by implementing your approach the Store is not loaded at all.

irfaniqbal
20 Jul 2011, 9:02 AM
hi andrea,
waiting for a reply with a solution. :)