如何从angularjs中的单选按钮列表中获取选定的值

时间:2015-10-08 09:29:46

标签: javascript angularjs

我有一个单选按钮列表,这些按钮的值来自ajax请求通知json data.i已将其绑定到列表但我想从列表中获取所选值,我尝试如下,没有运气。< / p>

HTML

   <ons-list-item modifier="tappable" ng-repeat="area in AreaList">
      <label class="checkbox checkbox--list-item" >
          <input type="radio" ng-bind="area.name"  ng-model="selectedValue" name="area" value="area.code">
        <div class="checkbox__checkmark checkbox--list-item__checkmark"></div>
        {{area.name}}
      </label>
    </ons-list-item>

JS

      //PARING FOR AREA
                if(data.Details[i] === "Area"){
                         for(var d=0;d<17;d++){

                             var area =data.Details[i+1][d]['varCityName'];
                             var code = data.Details[i+1][d]['intGlCode'];

                                 $scope.AreaList.push({name:area, code:code});

                                 area = '';
                                 code = '';

                                 $scope.selectedValue =  data.Details[i+1][d]['intGlCode'];

                    }

                    console.log("===========AREA obj===========",  $scope.AreaList);

       } 
.
.
.
.
 $scope.submitAnswer=function(list,rate,areaobj)
      {
       gList = list.name;

            alert("-----------my selected area is=========="+gArea);

     };

在console.long中打印的区域对象

[
    Object{
        name="Camana Bay",
        code="32"
    },
    Object{
        name="Breakers",
        code="1"
    },
    Object{
        name="Grand Cayman",
        code="2"
    },
    Object{
        name="Bodden Town",
        code="16"
    },
    Object{
        name="Cayman Brac",
        code="15"
    },
    Object{
        name="East End",
        code="20"
    },
    Object{
        name="George Town",
        code="21"
    },
    Object{
        name="George Town West",
        code="22"
    },
    Object{
        name="Little Cayman",
        code="23"
    }
   ]

1 个答案:

答案 0 :(得分:1)

尝试:

<input type="radio" ng-bind="area.name"  ng-model="selectedArea" name="area" ng-value="area.code">

ng-model 获取将存储所选值的变量。

如果将选择特定的单选按钮,

ng-value 将获取将存储在ng-model中的值

查看this jsbin