0

在下面的函数中,我得到了响应和长度perfiosAnalysisData

function getPerfiosData() {

      var tribeId = vm.currentTribeId;

      getPerfiosAnalysisData(tribeId).then(function(response){
        vm.perfiosAnalysisData = response.data;
        /* Check Select Option Length */            
            $scope.lengthData = vm.perfiosAnalysisData.institutions.length;     
        /* Check Select Option Length */        
        vm.isPerfiosEnabled = response.is_enabled;
        setChartDataConfig();
        getDrawGraph();
      },function(err){
        if(err.status === 412) {
          vm.perfiosNotPermitted = true;
        }
      });
    }

因此,如果长度为 1,我想自动选择选项并调用 ng-change 函数。

<select class="perf-select" ng-model="viewProfileCtrl.monthsForm.institution"
                           ng-options="inst.institution.institution_id as inst.institution.name for inst in viewProfileCtrl.perfiosAnalysisData.institutions"
                           ng-change="viewProfileCtrl.setCurrMonthInsti(viewProfileCtrl.monthsForm.institution)">
                           <option value=""  selected>Select a Bank
                        </select>

如何做到这一点?

4

1 回答 1

0

如果lengthData等于 1,则将第一个对象分配给 ng 模型变量并像这样调用 ng change 函数

function getPerfiosData() {
    var tribeId = vm.currentTribeId;
    getPerfiosAnalysisData(tribeId).then(function(response) {
        vm.perfiosAnalysisData = response.data;
        /* Check Select Option Length */
        $scope.lengthData = vm.perfiosAnalysisData.institutions.length;


        if ($scope.lengthData === 1) {
            $scope.viewProfileCtrl.monthsForm.institution = $scope.viewProfileCtrl.perfiosAnalysisData.institutions[0];
            $scope.viewProfileCtrl.setCurrMonthInsti($scope.viewProfileCtrl.monthsForm.institution);
        }


        /* Check Select Option Length */
        vm.isPerfiosEnabled = response.is_enabled;
        setChartDataConfig();
        getDrawGraph();
    }, function(err) {
        if (err.status === 412) {
            vm.perfiosNotPermitted = true;
        }
    });
}
于 2017-03-15T08:42:57.640 回答