【问题标题】:Wijgrid destroying data- attributesWijgrid 破坏数据属性
【发布时间】:2012-02-01 23:31:41
【问题描述】:

我有一些数据属性放入表格行标签中。 当我将表格设置为 wijgrid 时,数据属性将被破坏。

如何防止 wijmo 破坏这些属性?

【问题讨论】:

    标签: jquery-ui wijmo


    【解决方案1】:

    在行上应用属性 (tr) 时,插件会简单地忽略它们(正如您所经历的),无论它们是什么(样式、类、数据...)。

    这似乎是自愿的,因为通常会提取行属性的代码段已在插件源代码中注释

    readTableSection方法中,我们有(我在这里删除了不相关的代码行):

    readTableSection: function(table, section, readAttributes) {
    
        ...
    
        if (table && (section = this.getTableSection(table, section))) {
    
            for (ri = 0, rowLen = section.rows.length; ri < rowLen; ri++) {
    
                row = section.rows[ri];
                tmp = [];
    
                if (readAttributes) {
    
                    // here normally the html attributes of the rows (<tr>) should be extracted
                    // but the code is commented !
                    tmp.rowAttributes = null; // $.wijmo.wijgrid.getAttributes(row);
                    tmp.cellsAttributes = [];
    
                }
    
                // here is extracted the html attributes for the cells (<td>)
                for (ci = 0, celLen = row.cells.length; ci < celLen; ci++) {
                    tmp[ci] = row.cells[ci].innerHTML;
                    if (readAttributes) {
                        tmp.cellsAttributes[ci] = $.wijmo.wijgrid.getAttributes(row.cells[ci], prevent);
                    }
                }
    
                result[ri] = tmp;
            }
        }
    
        return result;
    }
    

    我在td 元素上使用“data-”属性进行了测试,它们没有被破坏。

    注意:您必须使用选项readAttributesFromData

    您可以联系开发此插件的公司,询问他们为什么将这行注释掉。

    【讨论】:

    • 现在这完全出乎意料。我知道他们在制作 wijmo-fied 网格时删除了属性。但希望有一些选择可以防止这种情况发生。我没想到它可能是导致它的错误或死代码。
    猜你喜欢
    • 1970-01-01
    • 2013-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-09
    • 2017-02-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多