这里我使用的是带有Web API的angularjs。我想获取选定的下拉列表值并分配到列表对象,然后它将保存到DB中。这是我的代码。
selectModule.controller("selectStateController", function ($scope) {
$scope.ILBasicInfoDTO.PYROrNonResidencyStateInfo.TaxpayerEarnedIncomeFromOtherState = { StateID: 10, StateName: 'Illinois' }, { StateID: 11, StateName: 'New York' }, { StateID: 12, StateName: 'Michigan' }, { StateID: 13, StateName: 'Georgia' }, { StateID: 14, StateName: 'California' };
$.ajax({
url: serviceUrl + 'il/persistilbasicinfo',
dataType: "json",
type: "POST",
async: true,
data: JSON.stringify({
userId: userId,
TaxReturnData:
{
UserDataId: userDataId,
TaxData: JSON.stringify($scope.ILBasicInfoDTO),
IsTaxMeterCall: false
},
}),
contentType: "application/json; charset=utf-8",
error: function (jqXHR, textStatus, errorThrown) {
ErrorHandling(jqXHR, errorThrown);
},
success: function (data, textStatus) {
if (data != null) {
}
}
})
});
<select id="ddlSpouseEearnedIncomeFromOtherState0" ng-model="ILBasicInfoDTO.PYROrNonResidencyStateInfo.TaxpayerEarnedIncomeFromOtherState">
<option value="">--Select--</option>
<option ng-repeat="TStatesExceptIL in TaxpayerStatesExceptILAndReciprocalStates" ng-value="TStatesExceptIL.StateId">{{TStatesExceptIL.StateCode}}</option>
</select>
答案 0 :(得分:0)
要获取所选文本和值,请将整个对象传递为ng-value
:
<select id="ddlSpouseEearnedIncomeFromOtherState0" ng-model="ILBasicInfoDTO.PYROrNonResidencyStateInfo.TaxpayerEarnedIncomeFromOtherState">
<option value="">--Select--</option>
<option ng-repeat="TStatesExceptIL in TaxpayerStatesExceptILAndReciprocalStates" ng-value="TStatesExceptIL">{{TStatesExceptIL.StateCode}}</option>
</select>
现在,您可以从已绑定到$scope
的{{1}}变量中获取文本和值,即ng-model
文字为:$scope.ILBasicInfoDTO.PYROrNonResidencyStateInfo.TaxpayerEarnedIncomeFromOtherState
值为:$scope.ILBasicInfoDTO.PYROrNonResidencyStateInfo.TaxpayerEarnedIncomeFromOtherState.StateCode