我有一个角度的foreach循环,如果我匹配一个值,我想从循环中断.以下代码不起作用.
angular.forEach([0,1,2], function(count){
if(count == 1){
break;
}
});
Run Code Online (Sandbox Code Playgroud)
我怎么能得到这个?
我知道解决方案不是很漂亮,但是我正在使用的模板需要它.
现在它可以工作,当产品在列表中时,它会向我显示"已添加"的span元素.
<section ng-repeat="product in products">
<label>
<input type="checkbox"
checklist-model="foobar.products"
checklist-value="product.id">
{{ product.name }}
</label>
<div ng-repeat="current_item in my.profile.items">
<span ng-show="product.id==current_item.id">Added</span>
</div>
</section>
Run Code Online (Sandbox Code Playgroud)
我想要的是,当复选框后面还出现"已添加"文本时,选中要选中的复选框.
我试过这样做:
<ng-checked="{{my.profile.items.array.thing}}">
Run Code Online (Sandbox Code Playgroud)
但那不起作用.因为数组中的产品如:
[{
id: 1, name:"Trinity",
id: 2, name:"Van Gogh",
id: 3, name:"Bonaqua",
}]
Run Code Online (Sandbox Code Playgroud)
这my.profile.items是一个包含更多信息的数组.因为它是我存储它的多对多关系.
有没有办法做到这一点?我不介意一个肮脏的解决方案:P
我试过这个:
// NG-check function
$scope.checkStoredValues = function(my) {
// Loop trought my current stored items
angular.forEach(my.profile.items, function(value, key) {
// Loop trough the array
angular.forEach(value, function(value, key) {
console.error(key);
// If key == 'id'
if(key == 'id'){ …Run Code Online (Sandbox Code Playgroud)