【问题标题】:How to display images instead of text in extJS treepanel如何在 extJS 树形面板中显示图像而不是文本
【发布时间】:2021-09-08 09:08:19
【问题描述】:

如何在 extJS 树形面板中显示图像而不是文本。

我正在使用拖放特性。那里我正在使用treeviewdragdrop 方法。

现在我想显示一些图像而不是文本。

这是我的代码。

{
            xtype: 'treepanel',
            align: 'stretch',
            rootVisible : false,
            title:'My Tree',
            useArrows: true,
            hideHeaders: true,
            scrollable: true,
            autoScroll: true,
            loadMask: {
                msg: 'Loading'
            },
            copy: true,
            rootVisible: false,
            viewConfig: {
                plugins: {
                    ddGroup: 'grid-to-form',
                    ptype: 'treeviewdragdrop',
                    appendOnly: true,
                    sortOnDrop: true,
                    enableDrag: true,
                    containerScroll: true,
                    allowParentInsert: false,
                    allowContainerDrops: false
                }
            },
        
        store: Ext.create('Ext.data.TreeStore', {
            root: {
                expanded: true,
                "text": ".",
                "children": [{
                    "item": "Box",
                    "iconCls": "tree-grid-task"
                },
                {
                    "item": "Date",
                    "iconCls": "tree-grid-task"
                },
                {
                    "item": "Number",
                    "iconCls": "tree-grid-task"
                },
                {
                    "item": "Text",
                    "iconCls": "tree-grid-task"
                },
                {
                    "item": "Field",
                    "editable":true
                }]
            }
        }),
        columns: [{
            xtype: 'treecolumn',
            text: '',
            dataIndex: 'item',

            flex: 2,
            sortable: true
        }]
    }

【问题讨论】:

    标签: javascript extjs extjs6


    【解决方案1】:

    您可以将渲染器放入树列中;我创建了一个fiddle 来展示它作为示例。

    {
      xtype: 'treecolumn',
      text: '',
      dataIndex: 'item',
      flex: 1,
      sortable: true,
      renderer: function(value, metaData, record, rowIndex, colIndex, store, view) {
        return '<img width=50 src="' + value + '"></img>';
      }
    }
    

    【讨论】:

    • flex 值不需要为 2。可以使用 flex: 1 ;)
    • @Dinkheller 我刚刚使用了问题中使用的同一列,但谢谢,我编辑了它
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多