Pregunta

I am trying to get a set of users using the SC.get() method through the SoundCloud API . I want the result set of users to have a follower_count between a ceiling and floor I set. follower_count is one of the provided references for a user object provided by SoundCloud.

I would like to get the result set described above using conditionals in the SC.get() method. Below is an example of what I'm trying to achieve:

var floor = 0;
var ceiling = 100;
SC.get('/users', { followers_count > floor && followers_count < ceiling }, .....)

Looking in the developer tab of chrome when I execute this code, I get the following error: "Uncaught SyntaxError: Unexpected token > "

This implies that the conditional operator ">" is not recognized within the SC.get() method. Is it possible to apply conditional statements to the references embedded in the SoundCloud api methods? Or is there some other way to achieve the same result?

Thank you for your help!

¿Fue útil?

Solución

Using jquery, you can add the condition in the callback by using an if clause.

SC.get('/users', function(users) {
    $.each( users, function( key, user ) {
        if(user.followers_count > floor && user.followers_count < ceiling) {  
            $("#result").append(user.username + ' (' + user.followers_count + ') <br/>');
        } 
    });

});

http://jsfiddle.net/iambnz/8Ue2t/

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top