angularjs 绑定多个属性到下拉框
Posted 帅就一个字却跟我一辈子
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了angularjs 绑定多个属性到下拉框相关的知识,希望对你有一定的参考价值。
绑定下拉框 angularjs 代码:
//活动下拉切换 $scope.activityChange = function () { var cards = new Array(); var url = "/CustomCard/GetCustomCardListByAct"; $.ajax({ url: url, type: ‘Get‘, async: false, data: { actName: $scope.formData.SelectActivityType }, success: function (data) { if (data != null) { $.each(data, function (i, n) { //, cu.IsBindDealerId,cu.IsBindVIN, cu.WriteOffNumber var cardinfo = { activity: n.ActivityType, cardid: n.CardType, cardtitle: n.CardTypeName, code: n.code, IsBindDealerId: n.IsBindDealerId, IsBindVIN: n.IsBindVIN, WriteOffNumber: n.WriteOffNumber } cards.push(cardinfo); }); $scope.cardTypes = cards; } }, error: function (err) { alert("error..."); } }); }
普通绑定下拉框 html 代码写法:
<div class="form-group"> <label class="col-md-2 control-label">卡劵类型:</label> <select ng-change="activityChangetype()" id="ii" class="col-md-2 form-control" ng-model="formData.SelectCardType" ng-options="m.cardid as m.cardtitle for m in cardTypes" > <option value="">请选择</option> </select> </div>
普通取值下拉框值写法:
//卡券类型下拉切换 $scope.activityChangetype = function () { console.log("选择了卡券类型"); //取到下拉框的Value console.log($scope.formData.SelectCardType); }
绑定多个属性到下拉框 html 代码写法:
<div class="form-group"> <label class="col-md-2 control-label">卡劵类型:</label> <select ng-change="activityChangetype()" id="ii" class="col-md-2 form-control" ng-model="formData.SelectCardType" ng-options="y.cardtitle for (x, y) in cardTypes"> <option value="">请选择</option> </select> </div>
多个属性取值:
//卡券类型下拉切换 $scope.activityChangetype = function () { console.log("选择了卡券类型"); console.log($scope.formData.SelectCardType.cardid); console.log($scope.formData.SelectCardType.IsBindDealerId); console.log($scope.formData.SelectCardType.IsBindVIN); console.log($scope.formData.SelectCardType.WriteOffNumber); if ($scope.formData.SelectCardType.WriteOffNumber>1) { console.log("选择的卡券可核销次数大于1"); // $scope.formData.MovingCode. } }
以上是关于angularjs 绑定多个属性到下拉框的主要内容,如果未能解决你的问题,请参考以下文章