【发布时间】:2015-04-29 16:55:58
【问题描述】:
这比预期的要困难得多。
我有两个数组:一个用于产品,一个用于选项。每个产品都应该有自己的一系列选项。
The problem starts when I try to give each product its own options array with its own scope, meaning when one option is selected it only pertains to that product's $scope and not any other.
有人建议我将 [$index] 添加到数组中,但这似乎不起作用。我无法检索此数组中的特定值。
options 数组有以下 id:(name,price,active)。在我尝试通过将活动布尔值设置为 true 并过滤这些结果来尝试执行此操作之前......但无论哪种方式都可以,简而言之,我需要检索所选选项的名称和价格值......
这不是最容易解释的,所以请耐心等待...感谢您的关注。
选项视图 html
<md-card ng-repeat="item in items.results | filter:true">
<img ng-src="{{item.img}}"
class="md-card-image"
alt="">
<md-card-content class="content">
<h2 class="md-title">{{ item.name }}</h2>
<h4>{{ item.price | currency }}</h4>
<md-list>
<p class="md-subhead">Choose Your Flavor</p>
<md-divider></md-divider>
<md-list-item ng-repeat="option in options.results"
layout="row">
<p> {{ option.name }} </p>
<span flex></span>
<p> {{ option.price | currency}} </p>
<md-checkbox aria-label="option.active"
class="md-accent"
ng-model="item.flavor[$index]">
</md-checkbox>
</md-list-item>
</md-list>
</md-card-content>
<md-action-bar layout="row"
layout-align="end center">
<md-button class="md-fab md-accent fab"
aria-label="Remove From Cart"
ng-click="remove(item)"
ng-class="{active:item.active}">
<md-icon md-svg-src="img/icons/remove.svg"></md-icon>
</md-button>
</md-action-bar>
</md-card>
这是我尝试使用这些值的顺序 html..
<md-card>
<md-card-content>
<md-list>
<span class="md-subhead">Review Order</span>
<md-divider></md-divider>
<md-list-item ng-repeat="item in items.results | filter:true"
layout="row">
<span>{{ item.name }}</span>
<span flex></span>
<span>{{ item.price | currency}}</span>
<span ng-repeat="flavor in item.flavor | filter:true">
{{flavor}}
</span>
</md-list-item>
<md-divider></md-divider>
<md-list-item layout="row">
<span>Order Total :</span>
<span flex></span>
<span>{{ total(items.results) | currency}}</span>
</md-list-item>
</md-list>
</md-card-content>
</md-card>
【问题讨论】:
标签: arrays angularjs angularjs-ng-repeat angular-ngmodel