[英]How to get value from table using Angular.js?
I need to get value from table according to the row using Angular.js. 我需要使用Angular.js根据行从表中获取价值。 I am providing my code:
我正在提供我的代码:
<tr ng-repeat="d in days">
<td>{{d.day_name}}</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',$index,catagory.value);" >
</select></td>
<td>
<select class="form-control" id="subcatagory[$index]" ng-model="subcatagory[$index]" ng-options="sub.name for sub in listOfSubCatagory[$index] track by sub.value " ng-change="setSubCatagory($index);" >
<option value="">Select Subcategory</option>
</select>
</td>
<td><input type="text" name="comment" id="comment" class="form-control oditek-form" placeholder="Add Comment" ng-model="comment[$index]" ng-keyup="comment($index);"></td>
</tr>
<input type="button" class="btn btn-success" ng-click="saveResturantDetails(billdata);" id="saveData" value="Save" style="margin-right:20px;"/> </div>
From above table I need to fetch the selected value and respective comment field value after click on save
button and stored them into a array. 从上表中,我需要在单击
save
按钮并将它们存储到数组后,获取选定的值和相应的注释字段值。 Here is my controller side code: 这是我的控制器端代码:
$scope.removeBorder=function(id,index,catvalue){
$scope.listOfSubCatagory[index]=[];
rowData['cat']=catvalue;
var catdata=$.param({'action':'subcat','cat_id':catvalue});
$http({
method:'POST',
url:"php/customerInfo.php",
data:catdata,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}).then(function successCallback(response){
angular.forEach(response.data,function(obj){
var data={'name':obj.subcat_name,'value':obj.subcat_id};
$scope.listOfSubCatagory[index].push(data);
})
},function errorCallback(response) {
})
}
$scope.saveResturantDetails=function(){
//here i want to collect data.
}
It seems that you're misunderstanding the two-way binding here. 看来您在这里误解了双向绑定。
Your data is already collected by ng-model
on whatever subcatagory[$index]
means. ng-model
使用任何subcatagory[$index]
手段收集了您的数据。 I'm guessing sugcatagory
is available on your $scope
, so you only have to iterate over the collection... 我猜想
sugcatagory
在$scope
上可用,因此您只需要遍历集合...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.