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);
                  })
              };
  • 相关阅读:
    (8)闭包函数(函数的传参方式)
    (7)名称空间和作用域
    (6)函数嵌套
    (5)函数对象
    (4)进阶函数(作用域、闭包、生成器、迭代器)
    (3)什么是函数(函数的定义、形参、实参、默认形参、可变长函数args kwargs,私有地址)
    (1)三元运算、字符编码
    (2)字符编码关系和转换(bytes类型)
    java技术学习网址收藏
    springmvc工作原理和环境搭建
  • 原文地址:https://www.cnblogs.com/bertha-zm/p/8042560.html
Copyright © 2011-2022 走看看