关于data-apos-ajax-append outside pieces-pages的说明

Explanation about data-apos-ajax-append outside pieces-pages

我想在我的项目中实现撇号 Ajax 功能,但遗憾的是我不完全理解 Ajax 功能。我一直在研究上周的文档,但我找不到关于该主题的足够信息。我想请问是否可以在 apostrophe-pieces-pages

之外使用 data-apos-ajax-append

我创建了一个这样的小部件:

lib/modules/infinite-widgets/index.js

module.exports = {
  extend: 'apostrophe-widgets',
  label: 'Infinite Widget',
  addFields: [
    {
      name: 'posts',
      label: 'Posts',
      type: 'array',
      titleField: 'name',
      schema: [
        {
          name: 'name',
          type: 'string',
          label: 'Name'
        },
        {
          name: '_image',
          type: 'joinByOne',
          withType: 'apostrophe-image',
          label: 'Image',
          required: true,
          filters: {
            projection: {
              attachment: 1,
              description: 1,
              title: 1
            }
          }
        }
      ]
    }
  ]
};
lib/modules/infinite-widgets/views/widget.html

<div class="row margin">
  <div class="col s12 m12">
    <div class="radius
      {% if data.widget.shadowOn == true %}
        z-depth-1
      {% endif %}
    ">
      <div data-apos-ajax-context="infinite">
        {% include "indexAjax.html" %}
      </div>
    </div>
  </div>
</div>
lib/modules/infinite-widgets/views/indexAjax.html

<div data-apos-ajax-append>
  {% for name in data.widget.posts %}
    {% set image = apos.images.first(name._image) %}
    <div class="card z-depth-0" style="
        {%- if piece.backColor-%}
          background-color:{{ piece.backColor }}
        {% endif %}
      ">
      <div class="card-image">
        <img src="{{ apos.attachments.url(image, { size: 'one-sixth' }) }}" />
      </div>
      <div class="card-content">
      {{ name.name }}
      </div>
    </div>
  {% endfor %}
</div>

这很好用,但不幸的是它显示了所有同时创建的帖子,我无法使用 "Load More..." button with AJAX here

{# Load More button. Also outside data-apos-ajax-append, so it gets refreshed #}
{% if data.currentPage < data.totalPages %}
  {# "Load More" button with the "append=1" flag #}
  <a href="{{ data.url | build({ page: data.currentPage + 1, append: 1 }) }}">Load More...</a>
{% endif %}

那么我可以修改这个查询,有一个加载更多按钮,或者更好地 data-apos-ajax-infinite-scroll 用于在小部件而不是一块中创建的数组的内容吗?

不,使用 data-apos-ajax-append 无法做到这一点。该功能专门用于 apostrophe-pieces-pages,例如,没有后端实现等待与它对话以获取小部件。

您应该改写 browser-side widget player for your widget, which gives you a place to make your own API calls back to the server. You can see that technique in the source of the apostrophe-twitter-widgets module