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);
                  })
              };
  • 相关阅读:
    【数学建模】—优秀论文(一)
    【数学建模】—论文排版
    【Linux学习】—第8章linux编程
    【Linux学习】—文件权限和目录配置
    【ESP8266学习】(一)
    【OpenCV】——b站达尔闻
    【Linux学习】——Shell编程基础
    【数学建模】——模拟退火算法(SAA)
    react 开发中火狐,Safari浏览器嵌套iframe显示空白
    element ui dataPicker 日期范围限制
  • 原文地址:https://www.cnblogs.com/bertha-zm/p/8042560.html
Copyright © 2011-2022 走看看