代码之家  ›  专栏  ›  技术社区  ›  HPWD

车把.js-在json数组上循环以确定是否应选中复选框

  •  0
  • HPWD  · 技术社区  · 6 年前

    我无法更改数据源,我必须使用所提供的内容。

    数据如下所示:
    [ [190, "some title here", 0, 100, 1, "https://www.somedomainhere.com", "", 8] ]

    这个 1

    {{#each myData}} <input type="radio" id="radio53" name="activityTypeID" value="1" {{#if_eq 4 1}}checked{{/if_eq}}> <input type="radio" id="radio54" name="activityTypeID" value="3" {{#if_eq 4 3}}checked{{/if_eq}}> <input type="radio" id="percentOfMax" name="activityTypeID" value="2" {{#if_eq 4 2}}checked{{/if_eq}}>{{/each}}

    我不知道如何评估 4 {{4}} 在我的车把模板中,它将显示为 1

    2 回复  |  直到 6 年前
        1
  •  1
  •   HPWD    6 年前

    这比我想象的要容易得多,我只需要 []

    {{#if_eq [4] 1}}checked{{/if_eq}}

    很好!

        2
  •  1
  •   Omolewa Stephen    6 年前

    做这些

    {{#if_eq [4] 1}}checked{{/if_eq}}