简体   繁体   English

AngularJS ng-repeat:更改数组

[英]AngularJS ng-repeat: Change Array

I want to change categoryAlpha into a different value (say, into categoryBeta ) in the following HTML + AngularJS: 我想改变categoryAlpha成不同的值(比方说,到categoryBeta下面的HTML + AngularJS):

 <div ng-repeat="x in categoryAlpha | limitTo:quantity"> <previews></previews> <hr /> </div> 

Since ng-repeat isn't a normal attribute, I don't think I can change it through jQuery attr() . 由于ng-repeat不是正常属性,因此我认为无法通过jQuery attr()进行更改。 Is my only solution regex, or is there an Angular/jQuery method that can change the value categoryAlpha ? 是我唯一的解决方案正则表达式,还是有可以更改值categoryAlpha的Angular / jQuery方法?

Thanks in advance. 提前致谢。

You can for example create function which will return a collection for ng-repeat and assign it to scope. 例如,您可以创建函数,该函数将返回ng-repeat的集合并将其分配给作用域。 Something like: 就像是:

// in your controller
$scope.getCategory = function getCategory() {
  return someCondition ? categoryAlpha : categoryBeta;
};

and then in your markup: 然后在您的标记中:

<div ng-repeat="x in getCategory() | limitTo:quantity">
  <previews></previews>
  <hr />
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM