1

这是用于 jquery 库的数据示例,但是我的数据是动态的,不是硬编码的。

var tree_data = {
    'for-sale' : {name: 'For Sale', type: 'folder'} ,
    'vehicles' : {name: 'Vehicles', type: 'folder'} ,
    'rentals' : {name: 'Rentals', type: 'folder'}   ,
    'real-estate' : {name: 'Real Estate', type: 'folder'}   ,
    'pets' : {name: 'Pets', type: 'folder'} ,
    'tickets' : {name: 'Tickets', type: 'item'} ,
    'services' : {name: 'Services', type: 'item'}   ,
    'personals' : {name: 'Personals', type: 'item'}
}

所以,我的问题是如果我有这个例如:

 var tree_data = {
        'for-sale' : {name: 'For Sale', type: 'folder'} ,
        'vehicles' : {name: 'Vehicles', type: 'folder'} 
}

我将如何添加

 rentals' : {name: 'Rentals', type: 'folder'}   ,
        'real-estate' : {name: 'Real Estate', type: 'folder'}   

在它已经创建之后的tree_data?

如果您可以为两者提供示例,我还需要为此代码执行此操作。

tree_data['for-sale']['additionalParameters'] = {
    'children' : {
        'appliances' : {name: 'Appliances', type: 'item'},
        'arts-crafts' : {name: 'Arts & Crafts', type: 'item'},
        'clothing' : {name: 'Clothing', type: 'item'},
        'computers' : {name: 'Computers', type: 'item'},
        'jewelry' : {name: 'Jewelry', type: 'item'},
        'office-business' : {name: 'Office & Business', type: 'item'},
        'sports-fitness' : {name: 'Sports & Fitness', type: 'item'}
    }
}
4

1 回答 1

2

如果您使用 jQuery.... 尝试使用 $.extend()

http://api.jquery.com/jQuery.extend/

否则...

var tree_data = {
        'for-sale' : {name: 'For Sale', type: 'folder'} ,
        'vehicles' : {name: 'Vehicles', type: 'folder'} 
};

tree_data['rentals'] = {name: 'Rentals', type: 'folder'}; 
tree_data['real-estate'] = {name: 'Real Estate', type: 'folder'};
于 2013-06-28T16:31:25.607 回答