0

私は LogMyCalls という会社で API を使用しており、最新の 5 件の通話を取得してリストに表示しようとしていますが、問題が発生しています。json がそれらからどのように出力されるかを次に示します。

{"status":"success","matches":3,"results":[{"tracking_number":"8556979885","disposition":"ANSWERED","duration":70,"external_id":null,"id":4918363,"is_outbound":0,"file_url":"http://s3.amazonaws.com/LogMyCalls/call_recordings/8556979885_4808898944_6024711995_20130801-214811.mp3?AWSAccessKeyId=**********&Expires=1378497578&Signature=*******","ouid":14104,"caller_id":"**********","calldate":"2013-08-01 21:48:11","status":"active","ringto_number":"**********","title":null,"user_id":null,"scored":false,"tagged":false},{"tracking_number":"8556979885","disposition":"ANSWERED","duration":49,"external_id":null,"id":4916465,"is_outbound":0,"file_url":"http://s3.amazonaws.com/LogMyCalls/call_recordings/8556979885_4808898944_5153091261_20130801-203535.mp3?AWSAccessKeyId=**********&Expires=1378497578&Signature=*******","ouid":14104,"caller_id":"**********","calldate":"2013-08-01 20:35:35","status":"active","ringto_number":"**********","title":null,"user_id":null,"scored":false,"tagged":false},{"tracking_number":"8556979885","disposition":"ANSWERED","duration":626,"external_id":null,"id":4911038,"is_outbound":0,"file_url":"http://s3.amazonaws.com/LogMyCalls/call_recordings/8556979885_4808898944_6028812248_20130801-162317.mp3?AWSAccessKeyId=**********&Expires=1378497578&Signature=*******","ouid":14104,"caller_id":"**********","calldate":"2013-08-01 16:23:17","status":"active","ringto_number":"**********","title":null,"user_id":null,"scored":false,"tagged":false}],"transaction_id":**********}

これは、よりきれいな外観の json です。

Array
(
[status] => success
[matches] => 3
[results] => Array
    (
        [0] => Array
            (
                [tracking_number] => 8556979885
                [disposition] => ANSWERED
                [duration] => 70
                [external_id] => 
                [id] => 4918363
                [is_outbound] => 0
                [file_url] => http://s3.amazonaws.com/LogMyCalls/call_recordings/8556979885_4808898944_6024711995_20130801-214811.mp3?AWSAccessKeyId=***********&Expires=1378497836&Signature=*******
                [ouid] => 14104
                [caller_id] => *********
                [calldate] => 2013-08-01 21:48:11
                [status] => active
                [ringto_number] => **********
                [title] => 
                [user_id] => 
                [scored] => 
                [tagged] => 
            )

        [1] => Array
            (
                [tracking_number] => 8556979885
                [disposition] => ANSWERED
                [duration] => 49
                [external_id] => 
                [id] => 4916465
                [is_outbound] => 0
                [file_url] => http://s3.amazonaws.com/LogMyCalls/call_recordings/8556979885_4808898944_5153091261_20130801-203535.mp3?AWSAccessKeyId=********&Expires=1378497837&Signature=*******
                [ouid] => 14104
                [caller_id] => ******
                [calldate] => 2013-08-01 20:35:35
                [status] => active
                [ringto_number] => **********
                [title] => 
                [user_id] => 
                [scored] => 
                [tagged] => 
            )

        [2] => Array
            (
                [tracking_number] => 8556979885
                [disposition] => ANSWERED
                [duration] => 626
                [external_id] => 
                [id] => 4911038
                [is_outbound] => 0
                [file_url] => http://s3.amazonaws.com/LogMyCalls/call_recordings/8556979885_4808898944_6028812248_20130801-162317.mp3?AWSAccessKeyId=*****&Expires=1378497837&Signature=*******
                [ouid] => 14104
                [caller_id] => ***********
                [calldate] => 2013-08-01 16:23:17
                [status] => active
                [ringto_number] => **********
                [title] => 
                [user_id] => 
                [scored] => 
                [tagged] => 
            )

    )

    [transaction_id] => *****
)

私が今使っているのは jQuery の次のコードです。最初の結果 ([0]) を取得できますが、何を考えても残りを取得することはできません。

function loadCalls(date1, id){
      $('#calltitle').empty();
      $('#calls').empty();
     $.getJSON("**********", 
          function(data) {

             var calldate = date1.toString('MMMM yyyy');
              $('#calltitle').html('Calls from ' + calldate);

              var callnum = 0;

              $.each(data['results'], function() {                
                  //if(data['results'][callnum].disposition == "ANSWERED") { var icon = 'icon-check'; } else { var icon = 'icon-check-empty'; };          
                  $('#calls').append('<li><div class="col1"><div class="cont"><div class="cont-col1"><div class="label label-info"><i class="' + 'icon-check' + '"></i></div></div><div class="cont-col2"><div class="desc">Call from ' + data['results'][callnum].caller_id + ' at ' + data['results'][callnum].calldate.toString('MMMM dd') + '</div></div></div></div><div class="col2"><div class="date">Just now</div></div></li>');
                  var callnum = callnum++;
              })
          }); 
  }

大変なことをしなければならなかったのは残念です、クライアントと私たちのために、そうしなければなりませんでした。

基本的に、私の jQuery では、次のすべての結果を取得する方法が必要です。

data['results'][0]
data['results'][1]
data['results'][2]
data['results'][3]
data['results'][4]

表示できる最大数は 5 で、上記は配列内のそれらへのルートですが、数を増やすことはできません (たとえば、JS で var callnum = 0; を設定しようとしましたが、 var callnum = callnum++; を使用してラウンドごとに増加させます (理論的には機能するはずですが、機能しませんでした)。

どんな助けでも大歓迎です!:)

4

1 に答える 1

0

するときはvar callnum = callnum++;、基本的に再割り当てします。

試す :

function loadCalls(date1, id){
      $('#calltitle').empty();
      $('#calls').empty();
     $.getJSON("**********", 
          function(data) {

             var calldate = date1.toString('MMMM yyyy');
              $('#calltitle').html('Calls from ' + calldate);

              var callnum = 0;

              $.each(data['results'], function() {                
                  //if(data['results'][callnum].disposition == "ANSWERED") { var icon = 'icon-check'; } else { var icon = 'icon-check-empty'; };          
                  $('#calls').append('<li><div class="col1"><div class="cont"><div class="cont-col1"><div class="label label-info"><i class="' + 'icon-check' + '"></i></div></div><div class="cont-col2"><div class="desc">Call from ' + data['results'][callnum].caller_id + ' at ' + data['results'][callnum].calldate.toString('MMMM dd') + '</div></div></div></div><div class="col2"><div class="date">Just now</div></div></li>');
                  callnum++;
              })
          }); 
  }
于 2013-09-06T16:21:13.230 に答える