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 绑定多个属性到下拉框的主要内容,如果未能解决你的问题,请参考以下文章

C#怎么实现下拉框动态绑定数据

angularJS 可编辑下拉选项框

SAPUI5 将下拉框的值绑定到另一个控件的属性

AngularJS:绑定到服务属性的正确方法

如何设置combobox 下拉框的内容

经验angularjs 实现带查找筛选功能的select下拉框