在 extjs4 中更改树节点背景颜色
changing the tree nodes background colour in extjs4
我是 JS 的新手,所以如果我问的是非常基本的问题,请原谅我。
我想更改我这里的树中节点的背景颜色。
Ext.application({
name: 'Autopsy',
launch: function() {
Ext.create('Ext.container.Viewport', {
layout: 'border',
items:[ {
......
.......
}, {
region:'west',
collapsible: true,
resizable: true,
title: 'Threads (Total: {{ num_threads|replace("\n","\n") }})',
width: 200,
layout: 'fit',
items: [
{
xtype: 'treepanel',
rootVisible: false,
store: threadStore,
lines: false,
useArrows: true,
}
]
}, {
.....
.....
ThreadSotre 是
var threadStore = Ext.create('Ext.data.TreeStore', {
root: {
text: 'Root',
expanded: true,
children: [
{% for thread in threadIds %}
{ text: "Thread {{ thread }}", leaf: true },
{% endfor %}
{ text: "Thread Ex", expanded: true, children: [
{ text: "funcTop", leaf: true },
{ text: "funcBottom", leaf: true},
{ text: "test", leaf: true}
] },
]
}
});
这给了我如下的输出
线程 6
线程 5
线程 4
线程 3
线程 2
线程 1
我希望 "Thread 1" 的背景色为红色。我该怎么做?
您可以使用树列渲染器更改节点的样式。示例代码如下。
xtype: 'treepanel',
rootVisible: false,
store: threadStore,
lines: false,
useArrows: true,
columns: [{
xtype : 'treecolumn',
text: 'Email',
dataIndex: 'name',
flex: 1,
renderer: function (value, metaData) {
//TODO Apply your logic here...
if(value==='Thread1'){
metaData.tdAttr = 'bgcolor="red"';
}
return value;
}
}
我是 JS 的新手,所以如果我问的是非常基本的问题,请原谅我。
我想更改我这里的树中节点的背景颜色。
Ext.application({
name: 'Autopsy',
launch: function() {
Ext.create('Ext.container.Viewport', {
layout: 'border',
items:[ {
......
.......
}, {
region:'west',
collapsible: true,
resizable: true,
title: 'Threads (Total: {{ num_threads|replace("\n","\n") }})',
width: 200,
layout: 'fit',
items: [
{
xtype: 'treepanel',
rootVisible: false,
store: threadStore,
lines: false,
useArrows: true,
}
]
}, {
.....
.....
ThreadSotre 是
var threadStore = Ext.create('Ext.data.TreeStore', {
root: {
text: 'Root',
expanded: true,
children: [
{% for thread in threadIds %}
{ text: "Thread {{ thread }}", leaf: true },
{% endfor %}
{ text: "Thread Ex", expanded: true, children: [
{ text: "funcTop", leaf: true },
{ text: "funcBottom", leaf: true},
{ text: "test", leaf: true}
] },
]
}
});
这给了我如下的输出
线程 6
线程 5
线程 4
线程 3
线程 2
线程 1
我希望 "Thread 1" 的背景色为红色。我该怎么做?
您可以使用树列渲染器更改节点的样式。示例代码如下。
xtype: 'treepanel',
rootVisible: false,
store: threadStore,
lines: false,
useArrows: true,
columns: [{
xtype : 'treecolumn',
text: 'Email',
dataIndex: 'name',
flex: 1,
renderer: function (value, metaData) {
//TODO Apply your logic here...
if(value==='Thread1'){
metaData.tdAttr = 'bgcolor="red"';
}
return value;
}
}