1

我所拥有的是一个填充了来自 ajax 的值的树形网格。每 30 秒刷新一次存储并显示新数据。

当它的值与旧的不同时,我需要更改 treegrid 单元格的样式(颜色或背景颜色)。要求是从 javascript 进行比较和样式设置。

关于如何做到这一点的任何想法?

4

1 回答 1

0

You could use dijit.Tree's getRowStyle method to modify the style dynamically. It will be called whenever a row needs to be rendered.

Something like this might get you started:

(function(){ // closure for private variables

var previousValues = {};

var myTree = ... // lookup dijit.Tree via dijit.byId, or create

myTree.getRowStyle = function(item){
    var style = {};
    var itemId = myTree.store.getIdentity(item);
    var newValue = myTree.store.getValue(item, "MY_ITEM_VALUE");
    if(newValue !== null &&
            previousValues[itemId] !== null &&
            previousValues[itemId] !== newValue) {
        style.backgroundColor = "#0000FF";
        previousValues[itemId] = newValue;
    }
    return style;
};

})();

There may be better ways to keep track of the previous values, but since your store is getting changed, I really can't think of one.

于 2011-11-02T04:00:06.420 回答