作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我试图将 html 表解析为 YUI 3 DataTable 小部件,修改小部件 HTML_PARSER 对象。
HTML
<div id="table">
<table>
<thead>
<tr>
<th>Tipo</th>
<th>Codigo</th>
<th>Descripcion</th>
<th>Impuesto para la Venta</th>
<th>Precio</th>
<th>Precio con IVA</th>
<th>Cantidad</th>
</tr>
</thead>
<tbody>
<tr>
<td>Producto</td>
<td>1</td>
<td>7</td>
<td>12</td>
<td>7.00</td>
<td></td>
<td>7</td>
</tr>
</tbody>
</table>
</div>
Javascript
Y.DataTable.HTML_PARSER = {
columns:function(srcNode) {
var cols = [];
srcNode.all("th").each(function(th){
var col = {
// sets column "key" to contents of TH with spaces removed
key: th.getHTML().replace(/\s+/g, '').toLowerCase(),
label: th.getHTML()
};
cols.push(col);
});
return cols;
},
data:function(srcNode) {
var data = [];
srcNode.all("tbody tr").each(function(tr){
var col = {};
tr.all("td").each( function(td_item, td_index){
// extracts the "key" name from the column based on it's TD index
var dataKey = Y.DataTable.HTML_PARSER.cols[td_index].key,
data = td_item.getHTML();
// sets "key:data" for this TD element ...
col[dataKey] = data;
});
data.push(col);
});
return data;
}
};
new Y.DataTable({srcNode:'#table'}).render('#table');
肯定有什么问题。也许我误读了documentation 。需要一些帮助。 PLAYGROUND
最佳答案
当您获取 dataKey 时,您正在调用方法 cols
而不是 columns
。顺便说一句,您不应该为每个单元格调用它,否则会太慢。在循环数据单元格之前将列键放入数组中并将它们保存在局部变量中。除此之外,它对我来说看起来不错,尽管我已经很久没有这样做了,并且可能会忘记一些东西。
苏尔特
关于javascript - 使 HTML_PARSER 在小部件 DataTable 中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17707594/
所以我试图将 html 表解析为 YUI 3 DataTable 小部件,修改小部件 HTML_PARSER 对象。 HTML Tipo Codigo Descripc
我上周将我的机器升级到了 Yosemite。现在,当尝试运行 pelican devserver 时,我得到一个 ImportError: $ ./develop_server.sh start St
我决定试试 pelican,但是当我运行 pelican-quickstart 时,我得到以下对话框: $ pelican-quickstart Traceback (most recent call
我是一名优秀的程序员,十分优秀!