javascript - extjs 4 : how to set the listview identity and pop up the id in the message box

标签 javascript extjs extjs4

Ext.require([
    'Ext.grid.*',
    'Ext.data.*',
    'Ext.panel.*'
]);
Ext.onReady(function(){
    Ext.define('ImageModel', {
        extend: 'Ext.data.Model',
        fields: ['id', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date', dateFormat:'timestamp'}]
    });
    var store = Ext.create('Ext.data.JsonStore', {
        model: 'ImageModel',
        proxy: {
            type: 'ajax',
            url: 'get-images.php',
            reader: {
                type: 'json',
                root: 'images'
            }
        }
    });
    store.load();

    var listView = Ext.create('Ext.grid.Panel', {
        width:425,
        height:250,
        collapsible:true,
        title:'Simple ListView <i>(0 items selected)</i>',
        renderTo: Ext.getBody(),

        store: store,
        multiSelect: true,
        viewConfig: {
            emptyText: 'No images to display'
        },

        columns: [{
            text: 'File',
            flex: 50,
            dataIndex: 'id'
        },{
            text: 'Last Modified',
            xtype: 'datecolumn',
            format: 'm-d h:i a',
            flex: 35,
            dataIndex: 'lastmod'
        },{
            text: 'Size',
            dataIndex: 'size',
            tpl: '{size:fileSize}',
            align: 'right',
            flex: 15,
            cls: 'listview-filesize'
        }]
    });

    // little bit of feedback
    listView.on('selectionchange', function(view, nodes){
        //pop up message on here.no idea
    });
});

问题

1)如何从数据库中设置listview行标识ID?当listview行被选中时,会弹出消息显示ID已被选中。但ID列无法显示。必须隐藏。

最佳答案

只需从列配置中删除"file"列并使用我在此处放入的 selectchange 事件中的代码:

Ext.require([
    'Ext.grid.*',
    'Ext.data.*',
    'Ext.panel.*'
]);
Ext.onReady(function(){
    Ext.define('ImageModel', {
        extend: 'Ext.data.Model',
        fields: ['id', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date', dateFormat:'timestamp'}]
    });
    var store = Ext.create('Ext.data.JsonStore', {
        model: 'ImageModel',
        proxy: {
            type: 'ajax',
            url: 'get-images.php',
            reader: {
                type: 'json',
                root: 'images'
            }
        }
    });
    store.load();

    var listView = Ext.create('Ext.grid.Panel', {
        width:425,
        height:250,
        collapsible:true,
        title:'Simple ListView <i>(0 items selected)</i>',
        renderTo: Ext.getBody(),

        store: store,
        multiSelect: true,
        viewConfig: {
            emptyText: 'No images to display'
        },

        columns: [{
            text: 'Last Modified',
            xtype: 'datecolumn',
            format: 'm-d h:i a',
            flex: 35,
            dataIndex: 'lastmod'
        },{
            text: 'Size',
            dataIndex: 'size',
            tpl: '{size:fileSize}',
            align: 'right',
            flex: 15,
            cls: 'listview-filesize'
        }]
    });

    // little bit of feedback
    listView.on('selectionchange', function(view, nodes){
        var nodeIdDisplay = "";
        for(var i = 0; i < nodes.length; i++)
        {
            if(nodeIdDisplay.length > 0)
                nodeIdDisplay += ",";
            nodeIdDisplay += nodes[i].get("id");
        }
        alert(nodeIdDisplay);
    });
});

关于javascript - extjs 4 : how to set the listview identity and pop up the id in the message box,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14902304/

相关文章:

javascript - extJS - 从同一 Controller 中的另一个函数调用一个函数

javascript - fs Node 模块的readFileSync是如何工作的?

javascript - 面板上的双击事件

ExtJS4:从 Ext.Application 访问全局变量

javascript - Ext JS - 版本变量增量

javascript - ASP.NET 中的 ExtJS 和 jQuery

javascript - 无法读取未定义的属性 'length'(使用地理服务器打印 map )

javascript - 通过 Websocket 到 WebGL 与 Canvas 的图像传输,也许还可以与工作人员一起传输

javascript - 我想将 div 用作 Twitter 引导模式链接

javascript - html2canvas:图像在 Firefox 上看起来模糊