【发布时间】:2017-03-19 07:07:30
【问题描述】:
在我的表(Handsontable)中,我有四列 Cars、A、B 和 C。 Cars 和 A 列的数据从 MySQL 数据库加载。 (如 PHP Demo)。
B 列的数据通过 AJAX 从 MySQL 数据库中填充,具体取决于 Cars 的值。代码如下:
{type: { renderer : function (instance, TD, row, col, prop, value, cellProperties) {
Handsontable.TextCell.renderer.apply(this, arguments);
var cr,prc;
cr = instance.getDataAtCell(row, 0);
prc = instance.getDataAtCell(row, 1);
$.ajax({
url: "php/act-go-t.php",
data: {cars: cr, price: prc},
dataType: 'json',
type: 'POST',
success: function (res) {
if (res.result[0].tax === null) {
TD.innerHTML = '0.000';
}
else {
TD.innerHTML = res.result[0].tax;
}
},
error: function () {
TD.innerHTML = '0.000';
}
});
}}}
C列是A和B的SUM,代码为:
{type : { renderer : function (instance, TD, row, col, prop, value, cellProperties) {
Handsontable.TextCell.renderer.apply(this, arguments);
var a,b;
a = instance.getDataAtCell(row, 1);
b = instance.getDataAtCell(row, 2);
TD.innerHTML = +a + +b;
}}}
问题是虽然 B 中加载了值,但添加不起作用。如果我将 B 列的类型设置为除 AJAX 之外的数字({type: numeric}),则添加工作正常。
AJAX 的结果:
+----------+------+-------+--------------+ | Cars | A | B | C | +----------+------+-------+--------------+ | Nissan | 20 | 10 | 20 | | Honda | 5 | 6 | 5 | +----------+------+-------+--------------+
没有 AJAX 的结果:
+----------+------+-------+-------------+ | Cars | A | B | C | +----------+------+-------+-------------+ | Nissan | 20 | 10 | 30 | | Honda | 5 | 6 | 11 | - +----------+------+-------+-------------+
如果我遗漏了什么,谁能告诉我?
【问题讨论】:
标签: javascript php handsontable