只是一个简单的问题,是否可以将 ng-model 中名为“id”的字符串连接到 angularjs 中的变量 product.id?有没有办法像这样的方法实际上可以工作?
这有效:
ng-model="currentQuantity['id1']"
Run Code Online (Sandbox Code Playgroud)
这不起作用:
ng-model='currentQuantity[id + "" + product.id]'
Run Code Online (Sandbox Code Playgroud)
一种可能的解决方法是使用二维变量来表示您的ng-model,即
ng-model='currentQuantity[id][product.id]'
Run Code Online (Sandbox Code Playgroud)
您需要引用字符串id,否则它将被评估为范围变量
改变:
ng-model='currentQuantity[id + "" + product.id]'
Run Code Online (Sandbox Code Playgroud)
到
ng-model='currentQuantity["id" + product.id]'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13876 次 |
| 最近记录: |