【问题标题】:href cell in a data grid Dojo数据网格 Dojo 中的 href 单元格
【发布时间】:2011-10-13 00:39:50
【问题描述】:

我找不到如何在 dojo 工具包数据网格中放置一个带 href 的单元格,我使用的 od dojo 版本是 1.6 这是我的桌子

  <table id="billsGrid" dojoType="dojox.grid.DataGrid" data-dojo-props="escapeHTMLInData:false">
        <thead>
            <tr>
                <th field="name" width="auto">name</th>
                <th field="description" width="auto">Description</th>
                <th field="activity" width="auto">activity</th>
            </tr>
        </thead>
    </table>

我正在使用 Json 获取数据。

【问题讨论】:

    标签: datagrid cell dojo dojox.grid


    【解决方案1】:

    您可以使用格式化函数来格式化单元格。例如,您可以声明一个包含所有格式化函数的 JavaScript 对象。

    var myFormatters = {
       formatLink : function(value, index) {
            return "<a href='#'>" + value + "</a>";
       }
    };
    

    然后在网格中,

    <table id="billsGrid" dojoType="dojox.grid.DataGrid" data-dojo-props="escapeHTMLInData:false" formatterScope="myFormatters"  >
        <thead>
            <tr>
                <th formatter="formatLink" field="name" width="auto">name</th>
                <th field="description" width="auto">Description</th>
                <th field="activity" width="auto">activity</th>
            </tr>
        </thead>
    </table>
    

    你不需要为格式化程序创建一个范围对象,那么这个格式化函数应该在全局范围内,然后你可以省略网格中的formatterScope属性。

    【讨论】:

    • 我还有一个问题,如何从 url 中获取参数,我的意思是如果有 page1.html?id=12345 ,我需要从 url 中获取 id,我知道在 Jquery 中是$.url.param("id");但在道场怎么样?
    • 您需要先使用window.location.href获取url,然后提取?之后的查询部分。得到查询字符串后,如id=12345&amp;name=alex,可以使用dojo.queryToObject将其转换为JSON对象{id:'12345', name:'alex'}
    【解决方案2】:

    出于安全原因,dojo 网格默认会转义 html 标签,您只需启用 html 标签即可:

    <table dojoType="dojox.grid.DataGrid" escapeHTMLInData="false" ...>
    

    或者如果你的网格是通过编程方式添加的

    escapeHTMLInData: false
    

    更多信息在这里: http://dojotoolkit.org/reference-guide/dojox/grid/DataGrid.html

    【讨论】:

      猜你喜欢
      • 2011-08-16
      • 2013-09-11
      • 1970-01-01
      • 2013-03-31
      • 2011-02-02
      • 2010-12-27
      • 2023-03-09
      • 2010-12-03
      • 1970-01-01
      相关资源
      最近更新 更多