无法使用Angular.js或Javascript将表中的行值设置为数组
我需要一个帮助。在使用Angular.js更改索引后,我需要在数组中设置一些值。我在下面解释我的代码无法使用Angular.js或Javascript将表中的行值设置为数组,javascript,arrays,angularjs,Javascript,Arrays,Angularjs,我需要一个帮助。在使用Angular.js更改索引后,我需要在数组中设置一些值。我在下面解释我的代码 <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 listOfCatagor
<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,subcatagory[$index].value);">
<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,comment[$index]);"></td>
</tr>
<input type="button" class="btn btn-success" ng-click="saveResturantDetails(billdata);" id="saveData" value="Save" style="margin-right:20px;"/>
在这里,我需要按行将所有行选择的值推送到数组中。请帮助我。创建3个字符串对象var Category、var SubCategory和var Comment 在保存函数中,将三个变量推送到Rowdata数组:
rowData.push({Cat:Category,SubCat:SubCategory,Comment:Comment})代码>你能简要介绍一下你的问题吗?@Vasanth:假设我从表格的每一行中选择了一些数据,并点击了保存按钮。所有数据都应该像这样收集并保存到数组中var arrData=[{'cat':1,'subcat':12,'comment':hii},{'cat':2,'subcat':22,'comment':hii},]
在子类别模型中选择一个标志。在设置子类别时,使此标志为真。在提交时,单击迭代子标记列表,并将isSelected is true模型添加到newarray@Vasanth:您能写下您的答案吗?它是否会获取所有行所选数据..?此var类别、var子类别和var注释将包含哪些内容。
将包含哪些内容。而不是rowData['cat']为变量类别变量赋值,如wise for subcat&comment。保存时,如上所示,将这3个变量值分配给数组对象
var rowData = {};
$scope.removeBorder = function(id, index, catvalue) {
$scope.listOfSubCatagory[index] = [];
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) {})
rowData['cat'] = catvalue;
}
$scope.setSubCatagory = function(index, subcatvalue) {
rowData['subcat'] = subcatvalue;
console.log('sub cat', rowData);
}
$scope.comment = function(index, comment) {
rowData['comment'] = comment;
}