Javascript 使用角度js为行中选定的输入框赋值
行添加使用角度代码。输入框型号名称为“代码”。当单击此输入框时,模型打开,当使用angularjs选择任何行时,当我使用$scope.code分配值时出现问题,它将分配给中的所有输入框,但我想分配执行ng单击的值Javascript 使用角度js为行中选定的输入框赋值,javascript,jquery,angularjs,Javascript,Jquery,Angularjs,行添加使用角度代码。输入框型号名称为“代码”。当单击此输入框时,模型打开,当使用angularjs选择任何行时,当我使用$scope.code分配值时出现问题,它将分配给中的所有输入框,但我想分配执行ng单击的值 <table class="table table-bordered table-hover table-condensed"> <tr style="font-weight: bold"> <td style="width:35%
<table class="table table-bordered table-hover table-condensed">
<tr style="font-weight: bold">
<td style="width:35%">Code</td>
</tr>
<tr ng-repeat="user in users">
<td>
<!-- editable username (text with validation) -->
<span ng-show="editDel">
@{{ user.name || 'empty' }}
</span>
@{{code}}
<input type="text" name="" ng-model="code" ng-show="saveCancel" ng-click="getCode()">
</td>
<td style="white-space: nowrap">
<!-- form -->
<form ng-show="saveCancel" class="form-buttons form-inline">
<button type="submit" class="btn btn-primary">
save
</button>
<button type="button" ng-click="isCancel()" class="btn btn-default">
cancel
</button>
</form>
<div class="buttons" ng-show="editDel">
<button class="btn btn-primary" ng-click="editUser($index)">edit</button>
<button class="btn btn-danger" ng-click="removeUser($index)">del</button>
</div>
</td>
</tr>
</table>
这是因为ng模型
对于每个输入
都是code
使用下面的代码示例进行更改
<input type="text" name="" ng-model="code_$index" ng-show="saveCancel" ng-click="getCode($index)">
现在,上述代码将更改每个输入字段的
ng模型
唯一性,并根据索引检索getCode中的值。每个ng重复项的模型应不同
编辑从getCode(user.code)到getCode(user)的更改
代码是作用域变量还是用户对象的属性?函数内部应该使用什么来为所选输入框$scope.getCode=function(code){$scope.user.code=“value”;}赋值?如果要为其赋值,请使用传入用户到
getCode(user)
然后在循环中通过用户获取具有相同id或任何唯一性的用户,然后分配亲爱的,我仍然无法将值分配给“ng model=“user.code”(已单击)。
<input type="text" name="" ng-model="user.code" ng-show="saveCancel" ng-click="getCode(user)">
$scope.getCode = function(user){
angular.forEach($scope.users, function (value, key) {
if (value.id == user.id) {
$scope.users[key]=user;
}
});
}