zoukankan      html  css  js  c++  java
  • 用angularJS获取select数据和之前选中的select的值(修改数据时select所选中的值)

    先定一个变量保存id和name,然后循环出来数据添加到该变量中,修改的时候就是比较当前这条数据的id是否跟循环出来的数据相等。

    html部分:

    <select ng-model="trains.name" class="form-control" ng-options="item.name for item in scenedata" ng-change="selectTastList(mytaskTypes)" style=" 130px;">
               <option value="">-- 请选择 --</option>
    </select>

    js部分:

    //查询
    $scope.seceneQuery = function () {
                  $scope.scenedata = [];
                  interfaceService.sceneQuery().then(function (response) {
                      if (response.data.success == false) {
                          toaster.pop('error', 'Error', response.data.message);
                          return false;
                      }
                      angular.forEach(response.data.data, function (item) {
                          $scope.scenedata.push({
                              'id': item.id,
                              'name': item.name
                          });
                      })
                      $scope.trains.name = $scope.scenedata[0].id;
                      console.log($scope.scenedata);
                      $scope.selectTastList();
                  }, function (error) {
                      $scope.toaster.text = 'Network error. Please try again later!';
                      toaster.pop('error', 'Error', $scope.toaster.text);
                  })
              }

    修改数据时select所选中的值的时候:

    $scope.openUpdateModel = function (item) {
                  $scope.scenedata = [];
                  var modalInstance = $modal.open({
                      templateUrl: 'modelu.html',
                      controller: 'ModaluCtrl',
                      scope: $scope
                  });
                  $scope.seceneQuery();
                  interfaceService.sceneQuery().then(function (response) {
                      if (response.data.success == false) {
                          toaster.pop('error', 'Error', response.data.message);
                          return false;
                      }
                      angular.forEach(response.data.data, function (i) {
                          //这里就是比较他们是否相等
                          if (i.id == item.sceneid) {
                              $scope.trains.name = i.id;
                          }
                      })
                  }, function (error) {
                      $scope.toaster.text = 'Network error. Please try again later!';
                      toaster.pop('error', 'Error', $scope.toaster.text);
                  })
              };
  • 相关阅读:
    HDU 1003——Max Sum(动态规划)
    HDU 2602 ——背包问题
    HDU 1850——Being a good boy
    HDU——2588 数论应用
    HDU1222——数论
    HDU1465——不容易系列之一(错排)
    URAL 2038 Minimum Vertex Cover
    772002画马尾
    CodeForces 19D Points
    The 2015 China Collegiate Programming Contest Game Rooms
  • 原文地址:https://www.cnblogs.com/bertha-zm/p/8042560.html
Copyright © 2011-2022 走看看