【发布时间】:2015-04-16 18:07:06
【问题描述】:
我对 js 比较陌生,现在必须在我们的项目中实现一个动手操作。
到目前为止,这运作良好,但我在全球化方面遇到了障碍。
基本上,我们使用逗号作为小数分隔符,但是当我尝试将“100,2”之类的内容复制到指定为“数字”的单元格中时,它将显示为 1002。
如果在指定为“文本”的单元格中输入相同的值,然后类型更改为数字,则该值将正确显示。
为此,我必须在表格源代码中添加“de”文化。(基本上复制“en”并更改当前与我相关的值。)
numeral.language('de', {
delimiters: {
thousands: '.',
decimal: ','
},//other non-relevant stuff here
当我直接从表中复制值并将它们插入到 np++ 时,它们显示为 100.2 等。但是,当将它们插入到 handsontable 中时,参数数组如下所示:
[Array[1], "paste", undefined, undefined, undefined, undefined]
0: Array[4]
0: 1 //row
1: 1 //column
2: "100.2" //previous value
3: 1002 //new value
这是我目前尝试过的:
hot.addHook("beforeChange", function () {
if (arguments[1] === "paste") {
hot.updateSettings({
cells: function (row, col, prop) {
var cellProperties = {
type: 'numeric',
language: 'en'
};
return cellProperties;
}
});
//hot.updateSettings({
// cells: function (row, col, prop) {
// var cellProperties = {
// type: 'text',
// };
// return cellProperties;
// }
//});
}
}, hot);
hot.addHook("afterChange", function () {
if (arguments[1] === "paste") {
ChangeMatrixSettings(); //reset cell properties of whole table
}
}, hot);
我希望我的问题已经足够清楚了,不确定我是否遗漏了什么。
是否有任何其他方法可以将正确的值返回到表中?这目前是不可能的吗?
提前致谢。
【问题讨论】:
标签: globalization handsontable