Ext.List 仅显示 1 个值而不是全部

发布于 2024-12-14 21:12:22 字数 1970 浏览 1 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陌路黄昏 2024-12-21 21:12:22

您正在 for 循环内创建 TabPanel,该循环为每个数组项创建一个 TabPanel,每个 TabPanel 都有一个绑定到具有单个记录的存储的列表。这些都是相互叠加的,因此您一次只能看到一个。

为了快速完成此操作,我会将 TabPanel 创建放在 for 循环之外,并在其中构建数据集:

var dataArray = [];
for (var i = 0; i < count; i++) {
   name = posts.data[i].name;

   dataArray.push({
                   firstName: name,
                   lastName: ''
              });
}

然后您可以将此 dataArray 传递到您的商店:

new Ext.data.JsonStore({
            model: 'Contact',
            sorters: 'firstName',

            getGroupString: function (record) {
              return record.get('firstName');
            },
            data:  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:

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文