tags:

views:

25

answers:

2

Hello, How do I go about calling a function within a jQuery array to add another array?

$('#map').zoommap({

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

        //Region
        map: function getMaps();

    });

getMaps() should return the following:

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

Cheers, Nick

+1  A: 

Pretty sure

map: getMaps()

Will do the trick. No ; at the end (just a comma if you need to add more items), and you don't need to put function before it either, unless you're trying to declare a function.

If you're questioning how to write the getMaps() function, you pretty much have that too..

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

Although I don't know why you need the function at all, when you could just put the inner { id: ... } right in it's place.... putting it all together:

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

    //Region
    map: {
        id: 'campus',
        image: '/resources/images/maps/'+mapId,
        data: '',
        maps: []
    }
});
Mark
That should do it.The reason for the function is because I'm going to eventually get the array via an ajax call.
Masey
Fair enough :) I prefer to call it a "dict" though, so as not to be confused with an actual `[]` array.
Mark
+1  A: 
$('#map').zoommap({

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

        //Region
        map: getMaps()

    });
Vaibhav Gupta