将css类添加到Ext.view.View Extjs 4中的节点

时间:2011-11-10 19:51:45

标签: css extjs4 nodes

我正在尝试将一个css类添加到Ext.view.View中的节点。我使用它来列出视图中的N个div并使它们可选。当选择其中一个div时,它应该改变颜色以识别它被选中。

Ext.create('Ext.view.View', {
    store: ...
    tpl: ...
    multiSelect: true,
    height: 310,
    trackOver: true,
    overItemCls: 'cell-wrap-hover',
    itemSelector: 'div.cell-wrap',
    emptyText: 'No item to show',
    plugins: [
        Ext.create('Ext.ux.DataView.DragSelector', {})
    ],
    listeners: {
        selectionchange: function(dv, nodes){
       if (nodes.length > 0) {
       for (var i in nodes) {
        //Here i would like to add one more css class to the nodes[0]
               }
    }

        }
    }

一旦我添加了这个新类,并保留了其他类,我可以使用新的类名作为Selector,对于View中的选定项,也可以使它们看起来不同。

1 个答案:

答案 0 :(得分:0)

我自己找到答案:在tpl中我为DIV选择器添加一个ID,例如:id =“cell-X”,其中X是一个索引(0,1,2 ...)。 然后进入foreach我使用命令行在所选节点上添加类:

Ext.get('cell-' + nodes[i].index).addCls('cell-wrap-selected');

感谢名单