0

我完全是新手...

我有一些 JSON

{
    "article": [
        {
            "id": "21",
            "type": "news",
            "title": "Lorem ipsum dolor sit amet, consectetur adipisicing elit.",
            "summary": "Lorem ipsum dolor sit amet, consectetur adipisicing elit.",
            "url": "http://www....",
            "website": "www...",
            "authors": [],
            "images": [
                {
                    "title": "",
                    "dateCreated": "",
                    "name": "",
                    "path": ""
                }
            ]
        },
        {
            "id": "22",
            "type": "news",
            "title": "Lorem ipsum dolor sit amet, consectetur adipisicing elit.",
            "summary": "Lorem ipsum dolor sit amet, consectetur adipisicing elit.",
            "url": "http://www....",
            "website": "www...",
            "authors": [],
            "images": [
                {
                    "title": "",
                    "dateCreated": "",
                    "name": "",
                    "path": ""
                }
            ]
        },
        {
            "id": "23",
            "type": "news",
            "title": "Lorem ipsum dolor sit amet, consectetur adipisicing elit.",
            "summary": "Lorem ipsum dolor sit amet, consectetur adipisicing elit.",
            "url": "http://www....",
            "website": "www...",
            "authors": [],
            "images": [
                {
                    "title": "",
                    "dateCreated": "",
                    "name": "",
                    "path": ""
                }
            ]
        }
    ]
}

这个 JSON 有超过 3 个元素。我不知道如何按这样的顺序模板 2,3,1,4,5,6,7,8,...

如何使用json循环一次模板,并将属性值放在我的html标签中?

我希望有

<ul>
  <li>
    <img scr="path to object 2">
    <a href="path to object 2">title of object 2</a>
  </li>
  <li>
    <img scr="path to object 3">
    <a href="path to object 3">title of object 3</a>
  </li>
  <li>
    <img scr="path to object 1">
    <a href="path to object 1">title of object 1</a>
  </li>
  <li>
    <img scr="path to object 4">
    <a href="path to object 4">title of object 4</a>
  </li>
  <li>
    <img scr="path to object 5">
    <a href="path to object 5">title of object 5</a>
  </li>
  ...
  <li>
    <img scr="path to object n">
    <a href="path to object n">title of object n</a>
  </li>
</ul>

有什么建议吗?

4

1 回答 1

0
{% for article in articles %}
  {% if loop.index == 2 %}
    <li>
      <img src="{{ article.images[0].path }}" />
      <a href="{{ article.url }}">{{ article.title }}</a>
    </li>
  {% endif %}
{% endfor %}
{% for article in articles %}
  {% if loop.index == 3 %}
    <li>
      <img src="{{ article.images[0].path }}" />
      <a href="{{ article.url }}">{{ article.title }}</a>
    </li>
  {% endif %}
{% endfor %}
{% for article in articles %}
  {% if loop.index == 1 %}
    <li>
      <img src="{{ article.images[0].path }}" />
      <a href="{{ article.url }}">{{ article.title }}</a>
    </li>
  {% endif %}
{% endfor %}

等等...

于 2014-12-09T00:05:46.027 回答