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);
                  })
              };
  • 相关阅读:
    FluorineFx:基于RSO(远程共享对象)的文本聊天室
    第一个十年,我从教师转行为web程序员,下一个十年呢?
    AS3中的单件(Singleton)模式
    数据结构C#版笔记双向链表(DbLinkList)
    FluorineFx:认证与授权
    FluorineFx:视频录制及回放(Flash/AS3环境)
    数据结构C#版笔记顺序表(SeqList)
    puremvc框架之hello world!
    flex中使用swc实现更好的界面代码分离
    puremvc框架之Command
  • 原文地址:https://www.cnblogs.com/bertha-zm/p/8042560.html
Copyright © 2011-2022 走看看