You have an array inside of an array, so playlist[0][0] should give
you the 'index' value.
From what I see, you should use the code you first posted, just moving
the playlist = []; declaration outside the function, leaving
everything else untouched. That way you'll have the playlist var
accessible.
I noticed you're trying to append the opening/closing tags for the UL.
That's not the way it works - you're probably ending up with two ULs
on the page with the items in between. You can't append pieces of mark-
up, only complete elements.
Change $("#layout_left_menu_float").append("<ul>");
to
var $ul = $('<ul/>').appendTo('#layout_left_menu_float');
$("#layout_left_menu_float").append(itemLink(index,title,type));
to
$ul.append(itemLink(index,title,type));
and remove
$("#layout_left_menu_float").append("</ul>");
Also you probably don't need $(document).ready() inside this function,
as it seems to be called from an event handler (the document is surely
loaded).
A quick rewrite: http://snipt.org/Vu
cheers,
- ricardo
On Apr 26, 7:49 pm, "[email protected]"
<[email protected]> wrote:
> I have tried this solution. The best I can get it to return is a 1 or
> a 0 in terms of array length, when it should be returning 5-10, as the
> script should be adding a sub array every time. I also can't seem to
> interact with it anywhere else, I have no idea what's going on. This
> is the newer code:
>
> var playlist = [];
> function ajaxMenu(whatTab){
> // retrieve the xml playlist
> $(document).ready(function(){
> playlist.length = 0;
> var id = 0;
> var title = '';
> // start menu
> $("#layout_left_menu_float").empty();
> $("#layout_left_menu_float").append("<ul>");
> // load the xml and run a foreach loop
> var xmlPlaylist = $.ajax({
> type: "GET",
> url: srcUrl+"playlist.xml",
> dataType: "xml",
> success: function(xml){
> $(xml).find('tab').each(function(){
> findTab =
> $(this).find('id').text();
> if(findTab !=
> whatTab){
> return true;
> }
> else {
> var i = '0';
>
> $(this).find('item').each(function(index){
> //
> Grab all details
> title
> = $(this).find('title').text();
> type
> = $(this).find('type').text();
> file
> = $(this).find('file').text();
> qt =
> $(this).find('qt').text();
> wmv =
> $(this).find('wmv').text();
>
> content = $(this).find('content').text();
>
> thumbnail = $(this).find('thumbnail').text();
>
> //
> Establish playlist item and add link
> var
> list = [index,title,type,file,qt,wmv,content,thumbnail];
>
> playlist = [list];
>
>
> $("#layout_left_menu_float").append(itemLink
> (index,title,type));
> });
> return false; //
> speed fix, ends once correct tab found
> }
> }); // end each
> }
> });
> // end menu
> $("#layout_left_menu_float").append("</ul>");
>
> }); // end document ready
> }
>
> Any ideas?
>
> Best regards,
> Robert May.
>
> On Apr 24, 1:50 pm, "[email protected]"
>
> <[email protected]> wrote:
> > I'm currently trying to build an array from an Ajax request, creating
> > a new object for each item in the query. Here's the code:
>
> > function ajaxMenu(whatTab){
> > // retrieve the xml playlist
> > $(document).ready(function(){
> > var id = 0;
> > var title = '';
> > // start menu
> > $("#layout_left_menu_float").empty();
> > $("#layout_left_menu_float").append("<ul>");
> > var playlist = new Array();
>
> > // load the xml and run a foreach loop
> > $.ajax({
> > type: "GET",
> > url: srcUrl+"playlist.xml",
> > dataType: "xml",
> > success: function(xml) {
> >
> > $(xml).find('tab').each(function(){
> > findTab =
> > $(this).find('id').text();
> > if(findTab !=
> > whatTab){
> > return true;
> > }
> > else {
> > var i = '0';
> >
> > $(this).find('item').each(function(index){
> > //
> > Grab all details
> >
> > title = $(this).find('title').text();
> >
> > type = $(this).find('type').text();
> >
> > file = $(this).find('file').text();
> > qt
> > = $(this).find('qt').text();
> > wmv
> > = $(this).find('wmv').text();
> >
> > content = $(this).find('content').text();
> >
> > thumbnail = $(this).find('thumbnail').text();
>
> > //
> > Establish playlist item and add link
> >
> > playlist[index] = new Object();
> >
> > playlist[index]['id'] = index;
> >
> > playlist[index]['title'] = title;
> >
> > playlist[index]['type'] = type;
> >
> > playlist[index]['file'] = file;
> >
> > playlist[index]['qt'] = qt;
> >
> > playlist[index]['wmv'] = wmv;
> >
> > playlist[index]['content'] = content;
> >
> > playlist[index]['thumbnail'] = thumbnail;
>
> >
> > $("#layout_left_menu_float").append(itemLink
> > (index,title,type));
> > });
> > return false; //
> > speed fix, ends once correct tab found
> > }
> > }); // end each
> > } // end success
> > }); // end $.ajax
> > // end menu
> > $("#layout_left_menu_float").append("</ul>");
> > }); // end document ready
> > }
>
> > This function builds a menu from the items in a playlist, but at the
> > same time I want to store the data in a global array to be used at any
> > time, until it is overwritten when a new menu is created.
>
> > How would I go about this?
> > Any help will be most appreciated!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"jQuery Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---