简体   繁体   English

extjs 4:列表视图选择图像ID并在其他面板上显示图像

[英]extjs 4: list view select image id and display the image on other panel

Ext.require([
    'Ext.grid.*',
    'Ext.data.*',
    'Ext.panel.*'
]);
Ext.onReady(function(){
    Ext.define('ImageModel', {
        extend: 'Ext.data.Model',
        fields: ['name', '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: 'name'
        },{
            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 l = nodes.length;
        var s = l != 1 ? 's' : '';
        listView.setTitle('Simple ListView <i>('+l+' item'+s+' selected)</i>');
    });
});

i have create 2 panel, one is left panel,second is right panel. 我创建了2个面板,一个是左侧面板,第二个是右侧面板。
the list view are created in the left panel,and the right panel will read the page showimage.php 列表视图在左侧面板中创建,右侧面板将读取页面showimage.php
list view are display file detail,when user select the list view will passing the file name as a parameter " name " to showimage.php, and the right panel will show the image by name are passed from list view select event.(actually the name field are stored file's ID) 列表视图是显示文件的详细信息,当用户选择列表视图时,会将文件名作为参数“ name ”传递给showimage.php,右侧面板将按名称显示图像,这些图像是从列表视图选择事件传递的。(实际上是名称字段是存储文件的ID)

Question

1)how to create the select list view event,when select a list view passing parameter name to showimage.php,and right panel refresh the page and display the image. 1)如何创建选择列表视图事件,当选择一个将参数名称传递给showimage.php的列表视图时,右侧面板刷新页面并显示图像。

//===========================LIST VIEW===============================
    Ext.define('ImageModel', {
        extend: 'Ext.data.Model',
        fields: ['PicID', 'PicUploadedDateTime','PicData']
    });

    var ImgStore = Ext.create('Ext.data.JsonStore', {
        model: 'ImageModel',
        autoLoad: true,
        proxy: {
            type: 'ajax',
            url: 'get-image.php',
            baseParams: {  //here you can define params you want to be sent on each request from this store
                        mainid: 'value1',
                        startdate: 'value2',
                        enddate: 'value3'
                        },
            reader: {
                type: 'json',
                root: 'images'
            }
        }
    });

    var listView = Ext.create('Ext.grid.Panel', {
        region: 'west',
        id : 'imagelist',
        title: 'Select Image',
        width: 200,
        split: true,
        collapsible: true,
        floatable: false,
        title:'Select Image',
        store: ImgStore,
        multiSelect: false,
        viewConfig: {
            emptyText: 'No images to display'
        },

        columns: [
            {
            text: 'Date Time Uploaded',
            //xtype: 'datecolumn',
            //format: 'Y-m-d H:i:s',
            flex: 65,
            width: 100,
            dataIndex: 'PicUploadedDateTime'
        }]
    });

    function hexToBase64(str) {
    return btoa(String.fromCharCode.apply(null, str.replace(/\r|\n/g, "").replace(/([\da-fA-F]{2}) ?/g, "0x$1 ").replace(/ +$/, "").split(" ")));
    }

    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("PicID");
        }
        */
        if (nodes[0].get("PicID") > 0){
            //alert(nodes[0].get("PicData"));
            image=Ext.getCmp('displayimage');
            image.setSrc("data:image/jpeg;base64,"+hexToBase64(nodes[0].get("PicData")));
        //console.log(nodes[0].get("PicData"));
        }
    });

this code method is post to the get-image.php,and get all the image in store and then, list view on select change event get the image id and display the image on type : 'image' component 此代码方法发布到get-image.php,并获取存储中的所有图像,然后,在select change事件上列出视图,获取图像ID,并在type : 'image'组件上显示该图像

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

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