代码之家  ›  专栏  ›  技术社区  ›  Nicoleta Wilskon

在ng repeat和ng change中传递两个值

  •  3
  • Nicoleta Wilskon  · 技术社区  · 8 年前

    var response = {
      "json": {
        "response": {
          "servicetype": "100",
          "functiontype": "101",
          "statuscode": "success",
          "data": [
            {
              "countryid": 1,
              "countryname": "India",
              "countrycode": "91",
              "currencyname": "Indian rupee",
              "currencycode": "INR",
              "latitude": "21.7679",
              "longitude": "78.8718"
            }
          ]
        }
      }
    }
    
      $scope.country = response.json.response.data;
    

    Html:

     <select name="Country" class="form-control1 drop countries" required  ng-model="model.country" placeholder="Select" value="India"  ng-change="getState(model.country);">
        <option value="" disabled selected> Country*</option>
        <option ng-repeat="item in country track by $index" value="{{item.countryid}}">{{item.countryname}}</option>
            </select>
    

    我想传递countryname和countryid来获取州列表,需要解决方案。我只能通过国家身份证。需要帮助。

    2 回复  |  直到 8 年前
        1
  •  2
  •   byteC0de    8 年前
    <select ng-model="country" required
        ng-options="c as c.countryname for c in country track by c.countryid" ng-change="getState(country.countryid, country.countryname);" >
        <option value="">Country*</option>
    </select>
    

    ng-options ,您将在国家模型中获得所有价值

        2
  •  1
  •   Maxim Shoustin    8 年前

    使用 ng-options 相反:

     <select  ng-model="model.country" required
        ng-options="c.countryid as c.countryname for c in country" >
        <option value="">Country*</option>
    </select>
    

    <select ng-model="model.country" required="" 
           ng-options="c.countryid as c.countryname for c in country" 
           class="ng-pristine ng-invalid ng-invalid-required">
        <option value="" class="">Country*</option>
        <option value="0">India</option>
    </select>
    

    Demo Fillde


    关于您的案例: track by $index select

    Demo Fillde 2