2010-09-02 51 views
0

我该如何去调用jQuery数组中的函数来添加另一个数组?调用数组中的函数

$('#map').zoommap({ 

     // Width and Height of the Map 
     width: '490px', 
     height: '380px', 

     //Region 
     map: function getMaps(); 

    }); 

getMaps()应返回以下:

{ 
    id: 'campus', 
    image: '/resources/images/maps/'+mapId, 
    data: '', 
    maps: [] 
} 

干杯, 尼克

回答

0

很肯定

map: getMaps() 

会做的伎俩。没有;最后(如果您需要添加更多项目,只需逗号),并且您不需要在它之前放置function,除非您尝试声明函数。

如果你质疑如何编写getMaps()功能,你很可能是太..

function getMaps() { 
    return { 
     id: 'campus', 
     image: '/resources/images/maps/'+mapId, 
     data: '', 
     maps: [] 
    } 
} 

虽然我不知道为什么你需要的功能在所有的时候,你可以只是把内{ id: ... }就在它的地方....把他们放在一起:

$('#map').zoommap({ 
    // Width and Height of the Map 
    width: '490px', 
    height: '380px', 

    //Region 
    map: { 
     id: 'campus', 
     image: '/resources/images/maps/'+mapId, 
     data: '', 
     maps: [] 
    } 
}); 
+0

应该这样做。 该函数的原因是因为我最终会通过ajax调用来获取数组。 – Masey 2010-09-02 04:34:42

+0

公平不够:)我更喜欢称它为“字典”,以免与实际的[]数组混淆。 – mpen 2010-09-02 05:04:34

0
$('#map').zoommap({ 

     // Width and Height of the Map 
     width: '490px', 
     height: '380px', 

     //Region 
     map: getMaps() 

    });