使用把手显示嵌套注释的最佳方法?

时间:2018-09-07 19:08:47

标签: javascript jquery html css handlebars.js

在通过递归局部显示所有数据方面,我有最初的部分,现在我的问题是弄清楚如何仅显示特定层数同时隐藏子级,直到单击“显示更多”链接。最后一层显示所有孩子。

数据摘要如下:

{
    "id": 1,
    "text": "Parent Comment 1",
    "generation": 0,
    "parentId": null,
    "children": [{"id": 3,
    "text": "Child of Parent 1",
    "generation": 1,
    "parentId": 1,
    "children": [
    {
        "id": 11,
        "text": "Child of Child Parent 1",
        "generation": 2,
        "parentId": 3,
        "children": [
        {
            "id": 12,
            "text": "Child of Child of Child Parent 1",
        "generation": 3,
        "parentId": 11
        },
    {
        "id": 5,
        "text": "Child of Parent 1",
        "generation": 1,
        "parentId": 1,
        "children": []
    }

在车把中,我使用局部渲染来嵌套嵌套在父级下的子级数组:

<script id="childPartial" type="text/x-handlebars-template">
    {{#each children as |comment|}}
    <section>

{{#if children}}
{{>childPartial comment}} {{! Recursively render the partial }}
{{/if}}
</section>
{{/each}}
</script>
<script id="comments-template" type="text/x-handlebars-template">

<div>
        {{#each comment_data as |comment|}} 

     </div>
        {{> childPartial comment}}


        </section>
        {{/each}} 
</script>

有没有一种方法可以使用可隐藏特定年龄段子代的把手来使助手说> 2,并向显示的最后一个子代添加“显示全部..”链接,然后单击该子代它会显示所有的孩子吗?还是在上下文模板化后使用jquery和操纵标记的最佳方法?

0 个答案:

没有答案