透视表在表中显示html [英] pivottable display html in table

查看:39
本文介绍了透视表在表中显示html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用https://github.com/nicolaskruchten/pivottable,基本上我想在表中显示图像。到目前为止,我所做的是;但它不会将图像显示为img标记,而是将其视为字符串

<body>
<script type="text/javascript">
$(function(){
    $("#output").pivotUI(
        [ 
            {product: "product1", image: "<img src='image1' alt='' height='42' width='42'>"}, 
            {product: "product2", image: "<img src='image2' alt='' height='42' width='42'>"}
        ]
    );
});
</script>

<p><a href="http://nicolas.kruchten.com/pivottable/examples/index.html">« back to examples</a></p>
<div id="output" style="margin: 10px;"></div>
</body>

推荐答案

由于表呈现器不支持th元素的html值,因此它明确设置了th的textContent属性,您必须创建自己的呈现器。 您有两个选择:

1.基于表渲染器代码创建渲染器,并将textContent更改为innerHTML。我将使用jsfiddle片段,因为呈现函数非常大:http://jsfiddle.net/u3pwa0tx/

2.重用现有的表格呈现器,该呈现器将html显示为纯文本,但在将其返回到要追加的父级之前,请将所有文本移动到html。

编辑:我在主存储库https://github.com/nicolaskruchten/pivottable/pull/214

上创建了拉取请求
$(function(){
    var rendererHtml = function(){
        var result = pivotTableRenderer2.apply(this,arguments);
        $(result).find('th').each(function(index,elem){
            var $elem = $(elem);
            $elem.html($elem.text());
        })
        return result;
    }

    $("#output").pivotUI(
        [ 
            {product: "product1", image: "<img src='image1' alt='' height='42' width='42'>"}, 
            {product: "product2", image: "<img src='image2' alt='' height='42' width='42'>"}
        ],{
            renderers:{
                'table2Renderer': rendererHtml
            }
        }
    );
 });

这篇关于透视表在表中显示html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆