Reputation: 1213
im using a AJAX request to get value from the server in a JSON format. but when i try to show this in the Ext.List only 1 value shows up instead of all.
Ext.setup({
onReady: function() {
Ext.regModel('Contact', {
fields: ['firstName', 'lastName']
});
var posts;
var count;
var name = 'sdf';
Ext.Ajax.request({
url: 'a.php/pool/listPools',
method: 'post',
type:'json',
success: function(response){
posts = Ext.decode(response.responseText);
alert(response.responseText);
count = posts.count;
for (var i = 0; i < count; i++) {
name = posts.data[i].name;
alert(name);
var btnContact = new Ext.TabPanel({
fullscreen: true,
items: [ new Ext.List({
itemTpl:'',
title: 'My Tab',
tpl: '<tpl for="."><div class="contact"><strong>{firstName}</strong> {lastName}</div></tpl>',
itemSelector: 'div.contact',
singleSelect: true,
grouped: true,
indexBar: false,
store: new Ext.data.JsonStore({
model: 'Contact',
sorters: 'firstName',
getGroupString: function (record) {
return record.get('firstName');
},
data: [
{
firstName: name,
lastName: ''
}
]
})
}),
//{ title: 'Tab 2' }
]
});
}}
});
}
});
Sooo my question is, how can i show all the retrieved data? instead of just 1?
Upvotes: 0
Views: 355
Reputation: 3258
You are creating your TabPanel inside the for loop which is creating one TabPanel per array item with each TabPanel having a List bound to a store with a single record. These are all on top of each other so you are only seeing one at a time.
To get this working quickly, I would take your TabPanel creation outside the for loop and build your data set within it:
var dataArray = [];
for (var i = 0; i < count; i++) {
name = posts.data[i].name;
dataArray.push({
firstName: name,
lastName: ''
});
}
You can then pass this dataArray to your store:
new Ext.data.JsonStore({
model: 'Contact',
sorters: 'firstName',
getGroupString: function (record) {
return record.get('firstName');
},
data: dataArray
})
I would suggest however that you look into how to make your stores load this data themselves (via proxies) as this is the best way to do it.
Stuart
Upvotes: 1