Reading data from array

Reading data from array

I am attempting to read XML information from a remote source into a javascript array. Upon retrieveing the XML, I load it into array by sections. I am doing this with the following code:

  1. $(theXML).find('person').each(
                    function($i){
                        $data.push({
                            firstname: $('name', this).text(),
                            lastname: $('lastname', this).text()
                        });
                    }
                );






My problem is I am attempting to list each of the persons by firstname. When a user clicks on each name, the associated lastname is loaded into a div. So the lastname is different each time a different firstname is clicked on.

The code is as follows:

  1. $($data).each(
                    function(){
                        $list_holder.append( $(document.createElement('li')).text($(this).attr('firstname')).click(
                            function(){
                                    alert( $(this).attr('firstname') );
                                  var lastname    =   $(this).attr('lastname');
                                  $('#edit-field-synopsis-0-value-wrapper #edit-field-synopsis-0-value').val( lastname );
                            }
                        ));
                    }
                );









The $list_holder(ul element) successfully appends each li object with the name of the department. Also, the click event is successfully attached.

The problem is, the description field of my array is inaccessible - I just can't reach the information i want, not even firstname.
I left in the alert statement deliberately - I can't get at 'firstname' either.

Below is an example of my XML file :

  1. <people>
        <person>
        <firstname title='colone'>Jack</firstname>
        <surname>O'neil</surname>
        </person>
       
        <person>
        <firstname title='Major'>Samantha</firstname>
        <surname>Carter</surname>
        </person>
       
        <person>
        <firstname title='Dr'>Daniel</firstname>
        <surname>Jackson</surname>
        </person>













  2. </peoplet>
Please, help me. I just spent a day on this.