1

我已经在这里发布了我的代码。在这里,我正在获取home_productsie的第一个节点的数据

    "contents": [
        {
            "id": "1",
            "product_name": "abc11"
        },
        {
            "id": "2",
            "product_name": "abc12"
        }
    ]

无法获取第二个节点的数据,即

    "contents": [
        {
            "id": "1",
            "product_name": "abc21"
        },
        {
            "id": "2",
            "product_name": "abc22"
        }
    ]

每次我得到相同的数据,即第一个节点的数据。

谁能帮我解决这个问题?

4

1 回答 1

1

FIXTURES的嵌套错误,你应该只有一个contents数组,导致:

Astcart.Application.FIXTURES=[
{
    "home_products": [
        {
            "id": "1",
            "name": "Mobiles & Accessories",
            "contents": [
                {
                    "id": "1",
                    "product_name": "abc11"
                },
                {
                    "id": "2",
                    "product_name": "abc12"
                },
                {
                    "id": "3",
                    "product_name": "abc21"
                },
                {
                    "id": "4",
                    "product_name": "abc22"
                },
                {
                    "id": "5",
                    "product_name": "abc31"
                },
                {
                    "id": "6",
                    "product_name": "abc32"
                }
            ]
        }
    ]
}
];

工作示例

希望能帮助到你。

更新

它缝合contents每个内部的嵌套数组home_product需要不同id的 's,尽管它们位于独立的数组中,否则它们会被视为一个并被覆盖:

更新的夹具

Astcart.Application.FIXTURES = [
  {
    "id": "1",
    "name": "Application 1",
    "home_products": [
      {
        "id": "1",
        "name": "Mobiles & Accessories",
        "contents": [
            {
                "id": "1",
                "product_name": "abc11"
            },
            {
                "id": "2",
                "product_name": "abc12"
            },
            {
                "id": "3",
                "product_name": "abc21"
            },
            {
                "id": "4",
                "product_name": "abc22"
            },
            {
                "id": "5",
                "product_name": "abc31"
            },
            {
                "id": "6",
                "product_name": "abc32"
            }
        ]
      },
      {
        "id": "2",
        "name": "Bags & Cases",
        "contents": [
            {
                "id": "7",
                "product_name": "def11"
            },
            {
                "id": "8",
                "product_name": "def12"
            },
            {
                "id": "9",
                "product_name": "def21"
            },
            {
                "id": "10",
                "product_name": "def22"
            },
            {
                "id": "11",
                "product_name": "def31"
            },
            {
                "id": "12",
                "product_name": "def32"
            }
        ]
      }
    ]
  }
];

更新的索引模板

<script type="text/x-handlebars" data-template-name="index">
  <ol>
    {{#each application in model}}
      <li>{{application.name}}</li>
        <ul>
          {{#each homeproduct in application.home_products}}
            <li>{{homeproduct.name}}</li>
              <ul>
                {{#each item in homeproduct.contents}}
                  <li>{{item.product_name}}</li>
                {{/each}}
              </ul>
          {{/each}}
        </ul>
    {{/each}}
  </ol>
</script>

更新了 jsfiddle。

于 2013-09-02T17:08:17.177 回答