我有一个hansontable,在页面加载时有30行。我将200行excel表复制/粘贴到javascript handontable表中,但是当我尝试计算行数(tr' s)时,它在Mozilla中得到80(在IE中为78)。更少的是Mozilla调试(F12)我做错了吗?
$('#btnShowMarkers').on('click', function(evt) {
var count = 0;
$("#example tr").each(function() {
count++
});
alert(count);
});
插件选项看起来像这样......
$('#example').handsontable({
data: data,
minSpareRows: 1,
maxRows : 999,
colHeaders: true,
contextMenu: true
});
答案 0 :(得分:0)
看看他们的例子,他们似乎使用特殊的 .handsontable('getData'); 方法。 这似乎现在效果更好......
<script src="../jquery/jquery.js" type="text/javascript"></script>
<script src="../handsontable/dist/jquery.handsontable.full.js"></script>
<link rel="stylesheet" media="screen" href="../handsontable/dist/jquery.handsontable.full.css">
<script type="text/javascript">
$( document ).ready(function() {
var data = [
["", "Maserati", "Mazda", "Mercedes", "Mini", "Mitsubishi"],
["2009", 0, 2941, 4303, 354, 5814],
["2010", 5, 2905, 2867, 412, 5284],
["2011", 4, 2517, 4822, 552, 6127],
["2012", 2, 2422, 5399, 776, 4151]
];
$('#example').handsontable({
data: data,
minSpareRows: 1,
maxRows : 999,
colHeaders: true,
contextMenu: true
});
$('#btnShowMarkers').on('click', function() {
var myTableData = $('#example').handsontable('getData');
var count = 0;
$.each( myTableData, function( index, myRow ) {
count = count + 1;
$('#output').append("row " + index + " >> " );
$.each( myRow, function( index, myCell ) {
$('#output').append(myCell + " - ");
});
$('#output').append("<br/>");
});
alert(count + " rows");
}); // end click
}); // end query
</script>
</head>
<div class="handsontable" id="example"></div><br/>
<button id='btnShowMarkers'>DUMP DATA</button>
<div id='output'></div>