简体   繁体   English

ExtJS如何在面板中显示存储数据

[英]ExtJS how to display store data in a panel

I want a display something like this in a panel: 我想要在面板中显示如下内容:

Title of the Panel 小组标题

TEST Address: 123 Land Dr, NY 12345 Address2: 234 Some Dr, CA 34590 测试地址:123 Land Dr,NY 12345 Address2:234 Some Dr,CA 34590

Test2 Address3: 123 Land Dr, NY 12345 Address4: 234 Some Dr, CA 34590 Test2地址3:纽约州12345的Land Dr,地址12345,地址4:CA 34590,234 Some Dr

I have created a model and a store which will return the data accordingly. 我已经创建了一个模型和一个存储,它将相应地返回数据。 How do I display this data? 如何显示这些数据? I created a panel as follows but I do not have a record to populate. 我创建了一个面板,如下所示,但是没有填充记录。 Is using XTemplate any easier? 使用XTemplate更容易吗? If yes, how can I use it? 如果可以,该如何使用?

Store: 商店:

Ext.define('BuildingInfoStore', {
    extend: 'Ext.data.Store',
    requires: ['BuildingInfoModel'], 
    model: 'BuildingInfoModel',
    storeId: 'BuildingInfoStore',

  data : [
         [ 'Address3', 'Address4', 'Address5', 'Address6' ]        
     ]
});

Panel: 面板:

Ext.define('BuildingInfo', {
    extend: 'Ext.panel.Panel',  
    autoScroll: true,
    initComponent: function () {

        items = [
        {
            xtype: 'fieldset',
            title: 'TEST',
            items :[
            {
               xtype: 'displayfield',
               fieldLabel: 'Address6' 
           }, 
           {
               xtype: 'displayfield',
               fieldLabel: 'Address5'
           }
           ]
       },
       {
        xtype: 'fieldset',
        title: 'TEST2',
        width: 700,
        items :[{
            xtype: 'displayfield',
            fieldLabel: 'Address4'
        }, 
        {
            xtype: 'displayfield',
            fieldLabel: 'Address3'
        }
        ]
    }

    this.items = items;
    this.callParent();
}
});

If using with a template, I am trying something like this (with Deepak P help from below answer) 如果与模板一起使用,我正在尝试类似的操作(从下面的答案中获得Deepak P的帮助)

{
            title: 'Building Details',
            id: 'westContainer',
            region:'west',
            xtype: 'panel',
            margins: '5 0 0 5',
            width: 550,
            split: true,         
            collapsible: true,              
            layout: 'fit',             
            items: [
             new Ext.DataView({
            store : 'ExtjsView.store.BuildingInfoStore',
            tpl:new Ext.XTemplate(
              '<div class="wrap">',
                '<tpl for=".">',       // process the data.kids node
                '<p>{#}. {name}, Address1: {address1},Address2: {address2}</p>',  // use current array index to autonumber
                '<p>Address3: {address3},Address4: {address4}</p></br>',
                '</tpl></div>'
            ),
            renderTo: Ext.getBody(),
              itemSelector: 'div.wrap',
              autoHeight : true,
              emptyText : 'No Data'
            })            
]           
},

Updated 更新

Your model: 您的模型:

Ext.define('BuildingInfoModel', {
    extend : 'Ext.data.Model',

    fields : [
        {
            name : 'address',
            type : 'string'
        },
        {
            name : 'address2',
            type : 'string'
        },
        {
            name : 'address3',
            type : 'string'
        },
        {
            name : 'address4',
            type : 'string'
        }
    ]
});

Your store: 您的商店:

Ext.define('BuildingInfoStore', {
    extend: 'Ext.data.Store',
    requires: ['BuildingInfoModel'], 
    model: 'BuildingInfoModel',
    storeId: 'BuildingInfoStore',

  data : [
         [ 'Address3', 'Address4', 'Address5', 'Address6' ]        
     ]
});

Try this and if you like it mark as answered: 试试这个,如果你喜欢它标记为已回答:

Ext.define('BuildingInfo', {
    extend: 'Ext.Panel',
    alias: 'widget.buildingInfo',
    xtype: 'buildingInfo',
    layout: 'form',
    resizable: true,
    border: 'fit',
    items: [{
        xtype: 'form',
        items: [{
            xtype: 'fieldset',
            title: 'TEST',
            items: [{
                xtype: 'displayfield',
                name: 'address4',
                fieldLabel: 'Address4'
            }, {
                xtype: 'displayfield',
                name: 'address3',
                fieldLabel: 'Address3'
            }]
        }, {
            xtype: 'fieldset',
            title: 'TEST2',
            width: 700,
            items: [{
                xtype: 'displayfield',
                name: 'address2',
                fieldLabel: 'Address2'
            }, {
                xtype: 'displayfield',
                name: 'address',
                fieldLabel: 'Address'
            }]
        }]
    }],
    listeners: {
        afterrender: function(component, eOpts){
            var store = Ext.getStore('BuildingInfoStore');
            if(!Ext.isEmpty(store)) {
                var form = component.down('form');
                form.loadRecord(store.last());
            }
        }
    }
});

You can paste this in sencha fiddle and check. 您可以将其粘贴在煎茶小提琴中并检查。

Ext.application({
    name : 'Fiddle',

    launch : function() {
        Ext.create('Ext.panel.Panel', {
            title: 'Hello',
            //TEST Address: 123 Land Dr, NY 12345 Address2: 234 Some Dr, CA 34590
            //Test2 Address3: 123 Land Dr, NY 12345 Address4: 234 Some Dr, CA 34590
            data:[{
                name: 'Test',
                address1: '123 Land Dr, NY 12345',
                address2: '234 Some Dr, CA 34590',
                address3: '123 Land Dr, NY 12345',
                address4: '234 Some Dr, CA 34590',
            },{
                name: 'Test123',
                address1: '123 Land Dr, NY 12345',
                address2: '234 Some Dr, CA 34590',
                address3: '123 Land Dr, NY 12345',
                address4: '234 Some Dr, CA 34590',
            }],
            tpl:new Ext.XTemplate(
                '<tpl for=".">',       // process the data.kids node
                '<p>{#}. {name}, Address1: {address1},Address2: {address2}</p>',  // use current array index to autonumber
                '<p>Address3: {address3},Address4: {address4}</p></br>',
                '</tpl>'
            ),
            renderTo: Ext.getBody()
        });
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM