2015-07-01 111 views
-1

我在JavaScript中有一個用於dataTables設置的對象。添加到javascript對象

var dataTableSettings = { 
    "iDisplayLength": 25, 
    "bLengthChange": false, 
    "bSortClasses": false, 
}; 

我再有一個if語句另一個選項添加到對象:

if (last_location) { 
    dataTableSettings.push(
    "oSearch": {"sSearch": last_location} 
); 
} 

我知道,不能因爲推()不上對象的工作了,我怎麼加到對象選項列表?

+0

'dataTableSettings.oSearch = { 「SSEARCH」:last_location}'? – putvande

回答

2
dataTableSettings.oSearch = { "sSearch": lastLocation }; 

或者

dataTableSettings['oSearch'] = { "sSearch": lastLocation }; 
1

你要做這樣說:

if (last_location) { 
    dataTableSettings.oSearch = {"sSearch": last_location}; 
} 

OR

if (last_location) { 
     dataTableSettings["oSearch"] = {"sSearch": last_location}; 
} 
0

只是這樣做:

dataTableSettings.oSearch = {"sSearch": last_location} 

或該(二者是等效的):

dataTableSettings['oSearch'] = {"sSearch": last_location}