1

私はfilter.jsをWordpress JSON APIとうまく連携させていますが、すべての投稿を出力するように JSON API に指示する必要がありましたが、指定する必要があります&count=-1(通常は 10 秒単位でページングされます)。

膨大な数の投稿がない場合はこれで問題ありませんが、追加されるほど、Wordpress JSON APIが JSON を生成するのに時間がかかります。

filter.jsはストリーミングを提供し、JSON ファイルのチャンクを取得してページに段階的に追加します。

本当の問題:

.json?offset=0&limit=50Wordpress JSON API のページ化された結果を使用するために、「ストリーミング」(AJAX 要求形式が ) を取得するにはどうすればよいですか? 新しいページごとに、新しいWordpress JSON API呼び出し&page=2などが必要です。

以下は私がこれまでに持っている関連コードですが、すべてここの貼り付けビンで見つけることができます: http://pastebin.com/EKhBddmh

apiLocation: '/api/get_posts/?post_type=business&count=-1',

settings: {
  filter_on_init: true,
  filter_criteria: {
    location: ['.js__filter-location .TYPE.any', 'taxonomy_business_location.ARRAY.slug'],
    type: ['.js__filter-type .TYPE.any', 'taxonomy_business_type.ARRAY.slug']
  },
  search: {
    input: '#filterSearch',
    search_in: '.media__title, .media__body, .media__footer'
  },
  filter_types: {
    any: function( current_value, option ){
      if ( current_value === '') { return true; }
      else { return current_value === option; }
    }
  },

  streaming: {
    data_url: filter.apiLocation,
    stream_after: 1,
    batch_size: 10
  },
}

init: function(){
  return FilterJS( filter.get_api_data( filter.apiLocation ).posts, '#resultsList', filter.view, filter.settings );
}


get_api_data: function( api_location ){

  var data;

  $.ajax({
    async: false, //thats the trick
    url: api_location,
    dataType: 'json',
    success: function( response ){
       data = response;
    }
  });

  return data;

},
4

1 に答える 1