【问题标题】:Display html in cell of datagrid in Dojo在 Dojo 的 datagrid 单元格中显示 html
【发布时间】:2012-01-20 10:59:01
【问题描述】:

我在 Dojo 1.6 中遇到了 DataGrid 的问题。我在 HtmlStore 上创建了 DataGrid,我想在最后一列链接中放入一些操作的单元格。我在文档中读到选项 escapeHtmlInData="false" 可以做到这一点,但它不起作用。我知道这很危险(XSS 攻击),但格式化程序的解决方案对我来说并不漂亮。所以我不知道为什么 escapeHtmlinData 不起作用。也许是 HtmlStore 的错?也许有人有类似的问题?我可以粘贴我的一段代码,但我使用 Django 和 dojango。

【问题讨论】:

  • 我解决了我的问题。这是 HtmlStore 的错。我扩展了这个类,并覆盖了函数 getValues()

标签: django datagrid hyperlink dojo cell


【解决方案1】:

对于其他人:

dojo.extend(dojox.data.HtmlStore,{
  getValues: function(item,attribute){

      this._assertIsItem(item);
      var index = this._assertIsAttribute(attribute);
      if(index>-1){
              var text;
              if(item.cells){
                      if({%for value in noEscapeData%}attribute=="{{value}}"{%if not forloop.last %} || {%endif%}{%endfor%}){
                              text = item.cells[index].innerHTML;
                      }else{
                              text = dojox.xml.parser.textContent(item.cells[index]);
                      }
              }else{//return Value for lists
                      text = dojox.xml.parser.textContent(item);
              }
              return [this.trimWhitespace?dojo.trim(text):text];
      }
      return []; //Array
  },
});

noEscapeData 是数组,其中列名不是转义数据

【讨论】:

    猜你喜欢
    • 2011-11-10
    • 2012-01-13
    • 1970-01-01
    • 2021-12-28
    • 1970-01-01
    • 1970-01-01
    • 2013-09-11
    • 1970-01-01
    • 2015-11-07
    相关资源
    最近更新 更多