【问题标题】:JSRender Reference Child Objects in ArrayJSRender 引用数组中的子对象
【发布时间】:2020-02-21 20:07:35
【问题描述】:

对 JSON/JSRender 完全陌生,只是尝试了一些我认为简单但无法为我的生活找到答案的东西..

我正在从 WEB API 导出以下数据,并希望使用 JSRender 将其呈现到文档中。我正在努力找出如何访问子对象“员工”并检索 98765 的“id”值

我认为这将是{{employee_training.employee.id}}但这似乎没有工作..

JSON 数据

"employee_training": [
        {
            "id": 1234,
            "name": "Training Course Alpha",
            "start_on": "2019-07-02",
            "end_on": "2019-07-02",
            "status": "Completed",
            "outcome": "Passed",
            "notes": "",
            "employee": {
                "id": 98765
            }

        }
]

【问题讨论】:

    标签: jsrender


    【解决方案1】:

    下面会遍历employee_training数组,输出员工id列表。

    {{for employee_training}}
      {{:employee.id}}
    {{/for}}
    

    请参阅 https://www.jsviews.com/#fortag@array 和 https://www.jsviews.com/#assigntag。

    【讨论】:

      猜你喜欢
      • 2020-12-03
      • 1970-01-01
      • 2020-12-03
      • 1970-01-01
      • 2016-05-24
      • 1970-01-01
      • 2019-10-03
      • 1970-01-01
      • 2011-06-05
      相关资源
      最近更新 更多