search

Home  >  Q&A  >  body text

angular.js - angular 中怎么在 repeat 的 item 中新建变量呢?

1.数据中只有x和y,我想在新建一个变量 item.x_y

<p ng-repeat="item in items">
  <span> {{item.x}} </span>
  <span> {{item.y}} </span>
  <span> {{item.x_y}} </span>
</p>

2.我还在在repeat中,自定义一个函数可行吗?item.function 只对这个item的数据操作

PHP中文网PHP中文网2744 days ago702

reply all(3)I'll reply

  • phpcn_u1582

    phpcn_u15822017-05-15 17:11:44

    I usually traverse the items,给每一项加x_yattributes.
    The performance is so poor, others must have a better way.

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-05-15 17:11:44

    Why not add attributes on the server side? Don’t put too much pressure on the front end. If this attribute is only for front-end display, it can be operated without adding the attribute. {{You can write your operation logic for xy here, try not to add attributes here}}. For example, if you want to add a new value of x-y, you can write it like this:
    {{item.x - item.y}}

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-05-15 17:11:44

    Add attributes to controller

    reply
    0
  • Cancelreply