我有这个javascript函数(它在.jade文件中虽然我很确定没有任何区别):
function setStopCommand(path, row)
{
if (row.sensor_active == 1)
{
var id = row.sensor_id;
var editSensorId_id = 'edit_sensor_id_' + id;
var editIpAddress_id = 'edit_ip_address_' + id;
var controlSelect_id = 'control-select_'+ id;
var params =
{
[editSensorId_id] : row.sensor_id,
[editIpAddress_id] : row.sensor_ip,
[controlSelect_id] : 4
};
console.log(JSON.stringify(params));
post(path, params);
}
}
这在现代(最新版本的Chrome)浏览器中运行良好。 stringify的输出类似于此(id可以根据发送命令的内容而改变):
{"edit_sensor_id_0C-29-ED-C7-DA":"0C-29-ED-C7-DA","edit_ip_address_0C-29-ED-C7-DA":"192.168.226.131","control-select_0C-29-ED-C7-DA":4}
但是,这不适用于我们在嵌入式设备上使用的旧版Chrome,并且无法升级Chrome。
如何实现相同的效果但符合旧版浏览器?我无法改变输出 - 它模仿命令来自较旧的系统。
StackOverflow上可能有一个答案,但由于我不知道该技术的名称是什么,我无法搜索它。
答案 0 :(得分:3)
旧浏览器不支持的问题是computed object properties,Chrome在版本49.0中添加了对它们的支持。
您可以使用旧语法轻松绕过此问题:
var id = row.sensor_id;
var editSensorId_id = 'edit_sensor_id_' + id;
var editIpAddress_id = 'edit_ip_address_' + id;
var controlSelect_id = 'control-select_' + id;
var params = {};
params[editSensorId_id] = row.sensor_id;
params[editIpAddress_id] = row.sensor_ip;
params[controlSelect_id] = 4;