我在javascript中有一个对象来设置dataTables。
var dataTableSettings = {
"iDisplayLength": 25,
"bLengthChange": false,
"bSortClasses": false,
};
然后我有一个if语句为对象添加另一个选项:
if (last_location) {
dataTableSettings.push(
"oSearch": {"sSearch": last_location}
);
}
我知道这不起作用因为push()不能处理对象,我该如何添加到对象选项列表?
答案 0 :(得分:2)
dataTableSettings.oSearch = { "sSearch": lastLocation };
或者
dataTableSettings['oSearch'] = { "sSearch": lastLocation };
答案 1 :(得分:1)
你必须这样做:
send(2)
OR
if (last_location) {
dataTableSettings.oSearch = {"sSearch": last_location};
}
答案 2 :(得分:0)
这样做:
dataTableSettings.oSearch = {"sSearch": last_location}
或者这(两者都是等价的):
dataTableSettings['oSearch'] = {"sSearch": last_location}