【问题标题】:Return first five values from spotify web service从 Spotify Web 服务返回前五个值
【发布时间】:2013-06-16 14:52:07
【问题描述】:

我正在使用 spotify web api 和 jquery ui 自动完成功能。我试图只返回响应中的前五个项目,而不是整个列表。

 <script type="text/javascript">
   $(function() {
    $("#spotify_song_search").autocomplete({
        source: function(request, response) {
            $.get("http://ws.spotify.com/search/1/artist.json", {
              //currently selected in input
                q: request.term
            }, function(data) {
                response($.map(data.artists, function(item) {
                    return {label: item.name, artist: item};
                }));
            });
        }
    });
});
</script>

谢谢

【问题讨论】:

    标签: jquery spotify


    【解决方案1】:

    只需使用slice() 剪切传递给 jquery map 函数的数组,因此,更改以下行:

     response($.map(data.artists, function(item) {
    

    对于这个:

     response($.map(data.artists.slice(0,5), function(item) {
    

    【讨论】:

      猜你喜欢
      • 2012-04-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多