1
我是新来的角,并遇到了我不知道设置此代码的最佳方式的场景。从基于另一个json文件的json文件中角度读取数据
我有2个JSON文件:
images.json
{
"imageName": "example.jpg",
"imageTags": ["fun","work","utility"]
"productID": ["item1","item3"]
}
products.json
{
"productID": "item1",
"productName": "Staple Gun",
"productURL": "Staple-Gun.htm"
}
我没有任何的代码,但,我真的试图让我确定我先建立这个正确的。
我的目标是根据标签拉取图像,所以我在第一个ng-repeat部分放了一个过滤器。这部分效果很好。但我希望能够链接到图像中的产品。我发现的最简单的方法是用productID作为过滤器进行ng-repeat,但如果我拉动50张照片,每张照片有2个项目,那么这是一大堆重复。在我看来,这需要大量的资源。这是最好的方式还是有更好的方法来处理这个问题?
代码例如:
<div ng-repeat="photo in photos | filter: 'fun'">
<img ng-src="{{ photo.imageName }}">
<span>Products In This Image</span>
<div ng-repeat="product in products | filter: photo.productID">
<a ng-href="{{ product.productURL }}" title="{{ product.productName }}">{{ product.productName }}</a>
</div>
</div>
这正是我一直在寻找。我认为必须有更好的方法来引用列表,而不必每次都重新加载列表。我的json文件很大,这应该会加速一些。 – zadees