Ext.List 仅显示 1 个值而不是全部
我使用 AJAX 请求从服务器获取 JSON 格式的值。 但是当我尝试在 Ext.List 中显示此值时,仅显示 1 个值而不是全部。
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' }
]
});
}}
});
}
});
所以我的问题是,如何显示所有检索到的数据?而不是只有 1 个?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在 for 循环内创建 TabPanel,该循环为每个数组项创建一个 TabPanel,每个 TabPanel 都有一个绑定到具有单个记录的存储的列表。这些都是相互叠加的,因此您一次只能看到一个。
为了快速完成此操作,我会将 TabPanel 创建放在 for 循环之外,并在其中构建数据集:
然后您可以将此 dataArray 传递到您的商店:
但是我建议您研究如何让您的商店加载此数据他们自己(通过代理),因为这是最好的方法。
斯图尔特
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:
You can then pass this dataArray to your store:
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