繁体   English   中英

pivottable在表格中显示html

[英]pivottable display html in table

我正在尝试使用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值,因此它明确设置了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
            }
        }
    );
 });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM