angularjs 触发同一行的项目以匹配第一列的用户输入
angularjs trigger items on same row to match user input on first column
<td align="center"><input type="number" name="test" ng-model="item.qty" ng-model-options="{ updateOn: 'blur' }" ng-change="Save(item.qty, item.qty2, item.include, {{$index}})" /></td>
<td align="center"><input type="number" name="test2" ng-model="item.qty2" ng-model-options="{ updateOn: 'blur' }" ng-change="Save(item.qty, item.qty2, item.include, {{$index}})" /></td>
<td align="center"><input type="checkbox" name="include" ng-model="item.include" ng-model-options="{ updateOn: 'blur' }" ng-change="Save(item.qty, item.qty2, item.include, {{$index}})" /></td>
这是我的 html 代码。有人可以告诉我是否有办法自动将第二个输入更改为与第一个输入相同的数字,并在用户填写完第一个数字后勾选第三个输入?
根据我收集到的您正在尝试做的事情,这将是解决方案。 qty2 将始终保持 == qty,如果 qty > 0,include 将为真。
HTML
<body ng-app="myApp" ng-controller="myCtrl">
<div ng-repeat="item in items">
<td align="center"><input type="number" name="test" ng-model="item.qty" ng-model-options="{ updateOn: 'blur' }" ng-change="Save(item)" /></td>
<td align="center"><input type="number" name="test2" ng-model="item.qty2" ng-model-options="{ updateOn: 'blur' }" ng-change="Save(item)" /></td>
<td align="center"><input type="checkbox" name="include" ng-model="item.include" ng-model-options="{ updateOn: 'blur' }" ng-change="Save(item)" /></td>
</div>
</body>
Angular
var app = angular.module("myApp", [])
.controller("myCtrl", ["$scope", function ($scope) {
$scope.items = [
{
qty: "",
qty2: "",
include: false
},
{
qty: "",
qty2: "",
include: false
},
];
$scope.Save = function (item) {
item.qty2 = item.qty;
item.include = item.qty > 0 ? true : false;
};
}]);
<td align="center"><input type="number" name="test" ng-model="item.qty" ng-model-options="{ updateOn: 'blur' }" ng-change="Save(item.qty, item.qty2, item.include, {{$index}})" /></td>
<td align="center"><input type="number" name="test2" ng-model="item.qty2" ng-model-options="{ updateOn: 'blur' }" ng-change="Save(item.qty, item.qty2, item.include, {{$index}})" /></td>
<td align="center"><input type="checkbox" name="include" ng-model="item.include" ng-model-options="{ updateOn: 'blur' }" ng-change="Save(item.qty, item.qty2, item.include, {{$index}})" /></td>
这是我的 html 代码。有人可以告诉我是否有办法自动将第二个输入更改为与第一个输入相同的数字,并在用户填写完第一个数字后勾选第三个输入?
根据我收集到的您正在尝试做的事情,这将是解决方案。 qty2 将始终保持 == qty,如果 qty > 0,include 将为真。
HTML
<body ng-app="myApp" ng-controller="myCtrl">
<div ng-repeat="item in items">
<td align="center"><input type="number" name="test" ng-model="item.qty" ng-model-options="{ updateOn: 'blur' }" ng-change="Save(item)" /></td>
<td align="center"><input type="number" name="test2" ng-model="item.qty2" ng-model-options="{ updateOn: 'blur' }" ng-change="Save(item)" /></td>
<td align="center"><input type="checkbox" name="include" ng-model="item.include" ng-model-options="{ updateOn: 'blur' }" ng-change="Save(item)" /></td>
</div>
</body>
Angular
var app = angular.module("myApp", [])
.controller("myCtrl", ["$scope", function ($scope) {
$scope.items = [
{
qty: "",
qty2: "",
include: false
},
{
qty: "",
qty2: "",
include: false
},
];
$scope.Save = function (item) {
item.qty2 = item.qty;
item.include = item.qty > 0 ? true : false;
};
}]);