我无法使用AngularJS从表中获取所选数据。
这是我的代码:
<tr ng-repeat="d in days">
<td>{{d.day}}</td>
<td>
<select class="form-control" id="catagory" ng-model="catagory" ng-options="cat.name for cat in listOfCatagory track by cat.value" ng-change="removeBorder('catagory');"></select>
</td>
<td>
<select class="form-control" id="subcatagory" ng-model="subcatagory" ng-options="sub.name for sub in listOfSubCatagory track by sub.value"></select>
</td>
<td>
<input type="text" name="comment" id="comment" class="form-control oditek-form" placeholder="Add Comment" ng-model="comment" ng-keypress="clearField('comment');">
</td>
</tr>
这里我需要当我从第一个选择字段中选择值时应该获取值,并且根据同一行,第二个选择字段将填充而不是其他行。
$scope.removeBorder = function(){
$scope.listOfSubCatagory = null;
$scope.listOfSubCatagory = [];
var catdata = $.param({
'action': 'subcat',
'cat_id': $scope.catagory.value
});
$http({
method: 'POST',
url: "php/customerInfo.php",
data: catdata,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}).then(function successCallback(response){
console.log('sub', response.data);
angular.forEach(response.data, function(obj) {
var data = {
'name': obj.subcat_name,
'value':obj.subcat_id
};
$scope.listOfSubCatagory.push(data);
})
}, function errorCallback(response) { })
}
我将category
值设为null
。