0

Hi guys can you please show me how to access the content inside the audioCollection object?

I am using the Echonest jQuery plugin with jQuery Templates

https://github.com/Rodeoclash/Echonest-jQuery-Plugin/blob/master/scripts/echonest.js

I went on firebug and typed console.log(audioCollection) and I am getting ReferenceError: audioCollection is not defined. Not sure if I am doing it right.

echonest.artist(artist).audio( function(audioCollection) {

$('#blog-page').find('.post').append( audioCollection.to_html('<p class="song-url" style="display:none;">${url}</p>') ); 
//appends url variable to html inside of audioCollection

var testing = audioCollection;  //returns [Object object]
});

Thank you!

4
  • Where exactly did you put console.log(audioCollection) ? Commented Feb 28, 2011 at 21:19
  • Are you using some plugin? If yes, which one? audio is not a standard jQuery function. You have to provide more information. Commented Feb 28, 2011 at 21:19
  • audioCollection only exists in the scope of its enclosing function. That's why you can't get its value from the global scope with Firebug. Commented Feb 28, 2011 at 21:22
  • Thank you Frederic! Felix I have updated the question with a link to the plugin I'm using. Commented Feb 28, 2011 at 21:24

2 Answers 2

2

I'm Not familiar with the object, but you can try to use my dump() function to see what's in it..

echonest.artist(artist).audio( function(audioCollection) {

    $('#blog-page').find('.post').append( audioCollection.to_html('<p class="song-url" style="display:none;">${url}</p>') ); 
    //appends url variable to html inside of audioCollection

    var testing = audioCollection;  //returns [Object object]
    alert(dump(testing));        
});

function dump(arr,level) {
    var dumped_text = "";
    if(!level) level = 0;

    //The padding given at the beginning of the line.
    var level_padding = "";
    for(var j=0;j<level+1;j++) level_padding += "    ";

    if(typeof(arr) == 'object') { //Array/Hashes/Objects 
        for(var item in arr) {
            var value = arr[item];

            if(typeof(value) == 'object') { //If it is an array,
                dumped_text += level_padding + "'" + item + "' ...\n";
                dumped_text += dump(value,level+1);
            } else {
                dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
            }
        }
    } else { //Stings/Chars/Numbers etc.
        dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
    }
    return dumped_text;
}

UPDATE

to access your values, you can do something like this

var songs = testing.audio;
for (var x=0; x<songs.length; x++){
    alert(songs[x].title);
}
Sign up to request clarification or add additional context in comments.

1 Comment

Hi it returned this: sharepaste.com/p/iyKbGL I would like to know how to access the values. I would appreciate anything to read on the subject
1

I you only want a raw view of the object, I'd suggest the widely used JSON.stringify():

echonest.artist(artist).audio(function(audioCollection) {
    console.log(JSON.stringify(audioCollection));

    // Appends url variable to html inside of audioCollection.
    $('#blog-page').find('.post').append(audioCollection.to_html(
        '<p class="song-url" style="display:none;">${url}</p>')); 
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.