如何在AngularJS中为ng-repeat赋值?

时间:2021-05-13 07:41:59

I have this code:

我有这个代码:

<ul ng-repeat="codes in response">
  <li ng-if="((codes.branch == formData.branches.alias) && (codes.taken == 0))">
    <strong>{{codes.id}}</strong> 
    {{codes.code}}
  </li>
</ul>

This checks if the code is taken from the database. Otherwise, it is displayed here. What I want to do now is to randomize the codes that are not yet taken and pick just one of those randomize codes and assign it to variable where I will then pass to a form data to store in a row along with the registered user's information. How do I pass values from ng-repeat to pass to the form then to the database?

这将检查代码是否来自数据库。否则,它会显示在此处。我现在要做的是随机化尚未采用的代码并选择其中一个随机代码并将其分配给变量,然后我将传递给表单数据以与注册用户的信息一起存储在一行中。如何将ng-repeat中的值传递给表单然后传递给数据库?

1 个解决方案

#1


Here's a conceptual answer:

这是一个概念性答案:

  1. In every ng-repeat loop, check if code is not taken. If not taken, push into Array UntakenCodes
  2. 在每个ng-repeat循环中,检查是否未采用代码。如果不采用,请进入Array UntakenCodes

  3. At the end of the loop, you have a list of untaken codes in an array.
  4. 在循环结束时,您有一个数组中未使用的代码列表。

  5. When your form submit happens, use a code at random (use Javascript's Math function to pick out one code from within the index bounds of the UntakenCodes array), and push that into the DB.
  6. 当您的表单提交发生时,随机使用代码(使用Javascript的Math函数从UntakenCodes数组的索引边界中挑选出一个代码),并将其推送到DB中。

Math.floor((Math.random() * upperBound) + lowerBound);

Math.floor((Math.random()* upperBound)+ lowerBound);

Where upperBound is the array length and lowerBound is 0

其中upperBound是数组长度而lowerBound是0

#1


Here's a conceptual answer:

这是一个概念性答案:

  1. In every ng-repeat loop, check if code is not taken. If not taken, push into Array UntakenCodes
  2. 在每个ng-repeat循环中,检查是否未采用代码。如果不采用,请进入Array UntakenCodes

  3. At the end of the loop, you have a list of untaken codes in an array.
  4. 在循环结束时,您有一个数组中未使用的代码列表。

  5. When your form submit happens, use a code at random (use Javascript's Math function to pick out one code from within the index bounds of the UntakenCodes array), and push that into the DB.
  6. 当您的表单提交发生时,随机使用代码(使用Javascript的Math函数从UntakenCodes数组的索引边界中挑选出一个代码),并将其推送到DB中。

Math.floor((Math.random() * upperBound) + lowerBound);

Math.floor((Math.random()* upperBound)+ lowerBound);

Where upperBound is the array length and lowerBound is 0

其中upperBound是数组长度而lowerBound是0