我将视图传递给控制器,然后将其存储到数组中。但之后我愿意抓住数组中的值并将其传递给update方法中的id值。
这就是我所拥有的
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>
这是我的控制器
$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)
有人建议使用
{id : $scope.plateid[0].plate_id,
但这不会奏效。
我坚持了一两天。有人帮忙。
答案 0 :(得分:0)
您正在将值推送到对象并尝试以错误的方式访问它。我创造了一个小提琴,它将解释它http://jsfiddle.net/az40Lxw8/2/
尝试以下
$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)