在动态选项卡中网格时 JSON 数据未显示?

发布于 2024-11-10 01:04:42 字数 3949 浏览 0 评论 0原文

我的网格在放入选项卡时不显示数据。该网格、存储、模型、JSON 在渲染到 body 或 div 或作为视口的一部分时起作用。只是放入选项卡时不显示,这也是使用 JSON 和 Tree 创建的!这是一个(有时)有效的示例。我不明白,也许范围错误......请帮助!

Ext.Loader.setConfig({ enabled: true });
Ext.require(['*']);
Ext.require('app.kontakt');
Ext.require('app.ponude');
Ext.require('app.gridStore');
Ext.onReady(function() {


Ext.create('Ext.Viewport', {
    layout: {
        type: 'border',
        padding: 5
    },
    defaults: {
        split: true
    },
    items: [{
        region: 'north',
        collapsible: false,
        split: true,
        height: 60
    },{
        region: 'west',
        collapsible: false,
        title: 'IZBORNIK',
        split: true,
        width: 200,
        layout: 'fit',
        items:[
       myTree
         ]

    },{
     region: 'center',
        layout: 'fit',
        border: false,
        items: [{
            xtype:'tabpanel',
            id:'mainTabPanel'
        }]
    }]
  });
});

var store = Ext.create('Ext.data.TreeStore', {
proxy: {
        type: 'ajax',
        url: 'app/myTree.json',
        },
reader: {
            type: 'ajax',
            root: 'nodes',
            record: 'leaf'
        }

});     

 var myTree = Ext.create('Ext.tree.Panel', {
 store: store,
 rootVisible: false,   
border: false,
listeners:{
    itemclick: function(view,record,item,index,e){

        if(record.isLeaf() && record.raw.tabCls){

            var tabId=record.raw.tabId;
            var mainPanel = Ext.getCmp('mainTabPanel');
            var existingTab = Ext.getCmp(tabId);

            if(existingTab){

                mainPanel.setActiveTab(existingTab);

            }else{

                mainPanel.add(Ext.create(record.raw.tabCls,{id:tabId})).show(); 
            }
        }
    }
}
});

Ext.define("app.kontakt",{
extend:"Ext.panel.Panel",
name:"kontakt",
title:"Kontakt",
layout:"border",
closable:true,
border: false,
items:[
        {
        region: 'north',
        collapsible: false,
        split:true,
        layout:"fit",
        height: 100,
        border: false,
        buttons: [{
            text: 'Load1',
            handler:function(){

                myStore.load({
                        scope : this,
                        url : 'app/kontaktGrid.json'
                });

            }
            },{
            text: 'Load2',
            handler:function(){

                myStore.load({
                        scope : this,
                        url : 'app/kontaktGrid1.json'
                });

            }
            }]              
        },{
        region: "center",
        xtype:"grid",
        id:"kontaktGrid",
        layout: "fit",
        store: myStore,
        border: false,
        columns: [
                {header: 'name',  dataIndex: 'name',flex:1},
                {header: 'email', dataIndex: 'email', flex:1},
                {header: 'phone', dataIndex: 'phone', flex:1}
            ]  
        }           
    ]       
});

Ext.define('app.gridStore', {
extend: 'Ext.data.Model',
fields: [
    'name', 'email', 'phone'
]
});

var myStore =Ext.create('Ext.data.Store', {
model: 'app.gridStore',
proxy: {
    type: 'ajax',
    url : '',
    reader:{ 
        type:'json',
        root: 'items'
    }
},
autoLoad:false


});

用于树的 JSON

{

    children: [
        { text:"KLIJENTI", expanded: true,
            children: [{ text:"Kontakt", leaf: true , tabId : "tab1", tabCls: "app.kontakt"}]
        }

    ]
}

用于网格的 JSON

{'items':[
    {"name":"Lisa", "email":"[email protected]", "phone":"555-111-1224"},
    {"name":"Bart", "email":"[email protected]", "phone":"555--222-1234"}
]}

My grid isnt showing data when put to tab. This grid, store, model, JSON are working when renderd to body or div, or as a part of a viewport. Only not showing when put in tab, that is also created using JSON and Tree! This is a (sometimes)working example. I cant figure it out, maybe scope bug ... Please help!

Ext.Loader.setConfig({ enabled: true });
Ext.require(['*']);
Ext.require('app.kontakt');
Ext.require('app.ponude');
Ext.require('app.gridStore');
Ext.onReady(function() {


Ext.create('Ext.Viewport', {
    layout: {
        type: 'border',
        padding: 5
    },
    defaults: {
        split: true
    },
    items: [{
        region: 'north',
        collapsible: false,
        split: true,
        height: 60
    },{
        region: 'west',
        collapsible: false,
        title: 'IZBORNIK',
        split: true,
        width: 200,
        layout: 'fit',
        items:[
       myTree
         ]

    },{
     region: 'center',
        layout: 'fit',
        border: false,
        items: [{
            xtype:'tabpanel',
            id:'mainTabPanel'
        }]
    }]
  });
});

var store = Ext.create('Ext.data.TreeStore', {
proxy: {
        type: 'ajax',
        url: 'app/myTree.json',
        },
reader: {
            type: 'ajax',
            root: 'nodes',
            record: 'leaf'
        }

});     

 var myTree = Ext.create('Ext.tree.Panel', {
 store: store,
 rootVisible: false,   
border: false,
listeners:{
    itemclick: function(view,record,item,index,e){

        if(record.isLeaf() && record.raw.tabCls){

            var tabId=record.raw.tabId;
            var mainPanel = Ext.getCmp('mainTabPanel');
            var existingTab = Ext.getCmp(tabId);

            if(existingTab){

                mainPanel.setActiveTab(existingTab);

            }else{

                mainPanel.add(Ext.create(record.raw.tabCls,{id:tabId})).show(); 
            }
        }
    }
}
});

Ext.define("app.kontakt",{
extend:"Ext.panel.Panel",
name:"kontakt",
title:"Kontakt",
layout:"border",
closable:true,
border: false,
items:[
        {
        region: 'north',
        collapsible: false,
        split:true,
        layout:"fit",
        height: 100,
        border: false,
        buttons: [{
            text: 'Load1',
            handler:function(){

                myStore.load({
                        scope : this,
                        url : 'app/kontaktGrid.json'
                });

            }
            },{
            text: 'Load2',
            handler:function(){

                myStore.load({
                        scope : this,
                        url : 'app/kontaktGrid1.json'
                });

            }
            }]              
        },{
        region: "center",
        xtype:"grid",
        id:"kontaktGrid",
        layout: "fit",
        store: myStore,
        border: false,
        columns: [
                {header: 'name',  dataIndex: 'name',flex:1},
                {header: 'email', dataIndex: 'email', flex:1},
                {header: 'phone', dataIndex: 'phone', flex:1}
            ]  
        }           
    ]       
});

Ext.define('app.gridStore', {
extend: 'Ext.data.Model',
fields: [
    'name', 'email', 'phone'
]
});

var myStore =Ext.create('Ext.data.Store', {
model: 'app.gridStore',
proxy: {
    type: 'ajax',
    url : '',
    reader:{ 
        type:'json',
        root: 'items'
    }
},
autoLoad:false


});

JSON for TREE

{

    children: [
        { text:"KLIJENTI", expanded: true,
            children: [{ text:"Kontakt", leaf: true , tabId : "tab1", tabCls: "app.kontakt"}]
        }

    ]
}

JSON for GRID

{'items':[
    {"name":"Lisa", "email":"[email protected]", "phone":"555-111-1224"},
    {"name":"Bart", "email":"[email protected]", "phone":"555--222-1234"}
]}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

⊕婉儿 2024-11-17 01:04:42

好的...我只需将您的代码复制粘贴到我的 firebug 即可(当然可以编辑 json url),
我收到一个错误...这是因为程序流程...
如果这是您的脚本,并将它们放在一个文件中,您可以

在此处存储代码对我起作用之前指定一个网格,没有错误...

Ext.onReady(function () {

    Ext.create('Ext.Viewport', {
        layout: {
            type: 'border',
            padding: 5
        },
        defaults: {
            split: true
        },
        items: [{
            region: 'north',
            collapsible: false,
            split: true,
            height: 60
        }, {
            region: 'west',
            collapsible: false,
            title: 'IZBORNIK',
            split: true,
            width: 200,
            layout: 'fit',
            items: [myTree]

        }, {
            region: 'center',
            layout: 'fit',
            border: false,
            items: [{
                xtype: 'tabpanel',
                id: 'mainTabPanel'
            }]
        }]
    });
});

var store = Ext.create('Ext.data.TreeStore', {
    proxy: {
        type: 'ajax',
        url: 'myTree.json',
    },
    reader: {
        type: 'ajax',
        root: 'nodes',
        record: 'leaf'
    }

});

var myTree = Ext.create('Ext.tree.Panel', {
    store: store,
    rootVisible: false,
    border: false,
    listeners: {
        itemclick: function (view, record, item, index, e) {

            if (record.isLeaf() && record.raw.tabCls) {

                var tabId = record.raw.tabId;
                var mainPanel = Ext.getCmp('mainTabPanel');
                var existingTab = Ext.getCmp(tabId);

                if (existingTab) {
                    mainPanel.setActiveTab(existingTab);
                } else {
                    mainPanel.add(Ext.create(record.raw.tabCls, {
                        id: tabId
                    })).show();
                }
            }
        }
    }
});



Ext.define('app.gridStore', {
    extend: 'Ext.data.Model',
    fields: ['name', 'email', 'phone']
});

var myStore = Ext.create('Ext.data.Store', {
    model: 'app.gridStore',
    proxy: {
        type: 'ajax',
        url: '',
        reader: {
            type: 'json',
            root: 'items'
        }
    },
    autoLoad: false
});

Ext.define("app.kontakt", {
    extend: "Ext.panel.Panel",
    name: "kontakt",
    title: "Kontakt",
    layout: "border",
    closable: true,
    border: false,
    items: [{
        region: 'north',
        collapsible: false,
        split: true,
        layout: "fit",
        height: 100,
        border: false,
        buttons: [{
            text: 'Load1',
            handler: function () {
                myStore.load({
                    scope: this,
                    url: 'grid.json'
                });
            }
        }, {
            text: 'Load2',
            handler: function () {

                myStore.load({
                    scope: this,
                    url: 'grid1.json'
                });

            }
        }]
    }, {
        region: "center",
        xtype: "grid",
        id: "kontaktGrid",
        layout: "fit",
        store: myStore,
        border: false,
        columns: [{
            header: 'name',
            dataIndex: 'name',
            flex: 1
        }, {
            header: 'email',
            dataIndex: 'email',
            flex: 1
        }, {
            header: 'phone',
            dataIndex: 'phone',
            flex: 1
        }]
    }]
});

ok... i have tes your code just by copy paste to my firebug (of course with edit the json urls),
and i got an error.... This is because the program flow...
if it was your script, and put them in a single file, you specify a grid before the store

here code works for me no error...

Ext.onReady(function () {

    Ext.create('Ext.Viewport', {
        layout: {
            type: 'border',
            padding: 5
        },
        defaults: {
            split: true
        },
        items: [{
            region: 'north',
            collapsible: false,
            split: true,
            height: 60
        }, {
            region: 'west',
            collapsible: false,
            title: 'IZBORNIK',
            split: true,
            width: 200,
            layout: 'fit',
            items: [myTree]

        }, {
            region: 'center',
            layout: 'fit',
            border: false,
            items: [{
                xtype: 'tabpanel',
                id: 'mainTabPanel'
            }]
        }]
    });
});

var store = Ext.create('Ext.data.TreeStore', {
    proxy: {
        type: 'ajax',
        url: 'myTree.json',
    },
    reader: {
        type: 'ajax',
        root: 'nodes',
        record: 'leaf'
    }

});

var myTree = Ext.create('Ext.tree.Panel', {
    store: store,
    rootVisible: false,
    border: false,
    listeners: {
        itemclick: function (view, record, item, index, e) {

            if (record.isLeaf() && record.raw.tabCls) {

                var tabId = record.raw.tabId;
                var mainPanel = Ext.getCmp('mainTabPanel');
                var existingTab = Ext.getCmp(tabId);

                if (existingTab) {
                    mainPanel.setActiveTab(existingTab);
                } else {
                    mainPanel.add(Ext.create(record.raw.tabCls, {
                        id: tabId
                    })).show();
                }
            }
        }
    }
});



Ext.define('app.gridStore', {
    extend: 'Ext.data.Model',
    fields: ['name', 'email', 'phone']
});

var myStore = Ext.create('Ext.data.Store', {
    model: 'app.gridStore',
    proxy: {
        type: 'ajax',
        url: '',
        reader: {
            type: 'json',
            root: 'items'
        }
    },
    autoLoad: false
});

Ext.define("app.kontakt", {
    extend: "Ext.panel.Panel",
    name: "kontakt",
    title: "Kontakt",
    layout: "border",
    closable: true,
    border: false,
    items: [{
        region: 'north',
        collapsible: false,
        split: true,
        layout: "fit",
        height: 100,
        border: false,
        buttons: [{
            text: 'Load1',
            handler: function () {
                myStore.load({
                    scope: this,
                    url: 'grid.json'
                });
            }
        }, {
            text: 'Load2',
            handler: function () {

                myStore.load({
                    scope: this,
                    url: 'grid1.json'
                });

            }
        }]
    }, {
        region: "center",
        xtype: "grid",
        id: "kontaktGrid",
        layout: "fit",
        store: myStore,
        border: false,
        columns: [{
            header: 'name',
            dataIndex: 'name',
            flex: 1
        }, {
            header: 'email',
            dataIndex: 'email',
            flex: 1
        }, {
            header: 'phone',
            dataIndex: 'phone',
            flex: 1
        }]
    }]
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文