0

我想从 Google 图书的书架上获取所有标题,并生成一串用逗号分隔的标题。这是我的尝试:

var allTitles = [];

$.getJSON("https://www.googleapis.com/books/v1/users/115939388709512616120/bookshelves/1004/volumes?key=MYAPIKEY",function(data){

     $.each(data.items, function (i, item) {

         allTitles.push(data.items[0].volumeInfo.title);

  });

var newTitleString = allTitles.join(', ');
    alert(newTitleString);   

http://jsfiddle.net/nathanbweb/YzXLW/

我该如何进行这项工作?

4

1 回答 1

0

好的,我能够从这个答案中弄清楚。这是有效的:

$.getJSON("https://www.googleapis.com/books/v1/users/115939388709512616120/bookshelves/1004/volumes?key=MYAPIKEY",function(data){

    var titles = [];

    data.items.forEach(function(e,i){titles.push(e.volumeInfo.title);});
         console.log(titles);

     var newTitleString = titles.join(', ');
         console.log(newTitleString);        

  });

http://jsfiddle.net/nathanbweb/YzXLW/3/

于 2014-03-26T15:05:56.170 回答