在jsrender中选择数组的一部分

Selecting part of array in jsrender

告诉我如何在jsrender中只选择部分数据

例如我有那个数组:

сatlist = [
{
    id: "1",
    title: "Category 1",
        products: [
        { name: "Child doc 1" },
        { name: "Child doc 2" }
    ]

},
    {
    id: "2",
    title: "Category 2",
        products: [
        { name: "Child doc 3" },
        { name: "Child doc4" }
      ]

    }
];

如何在模板中只显示id类别为2的子文档?

    <div id="peopleList"></div>

<script id="personTmpl" type="text/x-jsrender">
  <label>id:</label> {{:id}}<br/>
<label>name:</label> {{:title}}<br/>
{{if id==2}}
{{for products }}
<label>product name:</label> {{:name}}<br/>
{{/for}}
{{/if}}
</script>

var myTemplate = $.templates("#personTmpl");

var people = [
{
    id: "1",
    title: "Category 1",
        products: [
        { name: "Child doc 1" },
        { name: "Child doc 2" }
    ]

},
    {
    id: "2",
    title: "Category 2",
        products: [
        { name: "Child doc 3" },
        { name: "Child doc4" }
      ]

    }
];

var html = myTemplate.render(people);

$("#peopleList").html(html);

如果你想排除任何你可以做的事情,我把所有的代码都放在你可以自己排除的东西希望它会帮助你。