pivottable display html in table(透视表在表中显示html)
本文介绍了透视表在表中显示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属性,您必须创建自己的呈现器。
您有两个选择:
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
织梦狗教程
本文标题为:透视表在表中显示html
基础教程推荐
猜你喜欢
- Bokeh Div文本对齐 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
