I have the view passing values to the controller and I take this and store it into array. But afterwards I am willing to grab the value in the array and pass it into the value of id in update method.
我有视图将值传递给控制器,我把它拿到数组中。但之后我愿意抓住数组中的值并将其传递给update方法中的id值。
Here is what I have
这就是我所拥有的
HTML
<label class="control-label col-xs-8 col-sm-3 no-padding-right" >Choose a Plate</label>
<div class="col-xs-12 col-sm-9">
<select id="plateId" ng-model="selectedPlate" ng-options="plate as (plate.wafer_id + ' - ' + plate.serial_number) for plate in plates" ng-change="getSelectedPlateID(selectedPlate)"/>
<option value="">Select</option>
</select>
And here is my controller
这是我的控制器
$scope.plateid = [];
$scope.inspectionData = {
equipment_status_codes_id: 1,
plate_container_id: 1,
plate_container_slot: 21,
plate_quality_id: 1
}
PlatesFactory.query(function(plates)
{
$scope.plates = plates;
});
$scope.getSelectedPlateID = function(item)
{
$scope.plateid.push({
plate_id : item.id
});
console.log($scope.plateid[0]);
//alert(item.wafer_id)
}
// I have no clue what I am doing wrong here, but it just not working. I can't seem to update the object on the database
PlatesInspectionFactory.update( {id : $scope.plateid[0]}, $scope.inspectionData)
someone here suggested using
有人建议使用
{id : $scope.plateid[0].plate_id,
but this wont work.
但这不会奏效。
I am stuck with this like for a day or two. Somemone help please.
我坚持了一两天。有人帮忙。
1 个解决方案
#1
0
You are pushing values to object and trying to access it in wrong way. I have created a fiddle which will explain it http://jsfiddle.net/az40Lxw8/2/
您正在将值推送到对象并尝试以错误的方式访问它。我创造了一个小提琴,它将解释它http://jsfiddle.net/az40Lxw8/2/
Try below
$scope.plateid = [];
$scope.inspectionData = {
equipment_status_codes_id: 1,
plate_container_id: 1,
plate_container_slot: 21,
plate_quality_id: 1
}
PlatesFactory.query(function(plates)
{
$scope.plates = plates;
});
$scope.getSelectedPlateID = function(item)
{
$scope.plateid.push({
plate_id : item.id
});
console.log($scope.plateid[0]);
//alert(item.wafer_id)
}
// I have no clue what I am doing wrong here, but it just not working. I can't seem to update the object on the database
PlatesInspectionFactory.update( {id : $scope.plateid[0].plate_id}, $scope.inspectionData)
#1
0
You are pushing values to object and trying to access it in wrong way. I have created a fiddle which will explain it http://jsfiddle.net/az40Lxw8/2/
您正在将值推送到对象并尝试以错误的方式访问它。我创造了一个小提琴,它将解释它http://jsfiddle.net/az40Lxw8/2/
Try below
$scope.plateid = [];
$scope.inspectionData = {
equipment_status_codes_id: 1,
plate_container_id: 1,
plate_container_slot: 21,
plate_quality_id: 1
}
PlatesFactory.query(function(plates)
{
$scope.plates = plates;
});
$scope.getSelectedPlateID = function(item)
{
$scope.plateid.push({
plate_id : item.id
});
console.log($scope.plateid[0]);
//alert(item.wafer_id)
}
// I have no clue what I am doing wrong here, but it just not working. I can't seem to update the object on the database
PlatesInspectionFactory.update( {id : $scope.plateid[0].plate_id}, $scope.inspectionData)