【问题标题】:Get selected value to use in if statement获取要在 if 语句中使用的选定值
【发布时间】:2016-02-27 04:01:17
【问题描述】:

我正在尝试使用 ngoptions 和 ngchange 验证选择下拉列表中的内容。 例如,如果选中的内容是“票”,那么它将显示提交按钮。

目前,在我看来(前端)有 Jade:

Select(ng-model='angReporting' ng-options="r.reporting for r in 
incategory" style="width:100px;" ng-change="ifChange(angReporting)" )
br
a.btn.btn-primary.btn-sm(ng-click="incidentsCreate()" ng-hide="validate(status)") 
Submit

以上是一个简短的示例,我有一组链式选择(angularjs)正在工作。 为了验证是否选择了正确的内容,我的模块上有以下内容:

$scope.itemList=[];

$scope.ifChange=function(item){
    $scope.itemList.push(item.reporting);

    for (var i=0; i < $scope.itemList.length; i++){
      if($scope.itemList[i] === 'Ticket'){
        $scope.validate = {status: false};
      }
    }
  };

范围的 json 内容简而言之:

 $scope.incategory = [
    {

      'reporting':'Incident',
      'content':[
        {
          ...
        }
      'reporting':'Ticket',
      'content':[
        {
          ...
        }

提前感谢您分享您的想法 最好的问候

【问题讨论】:

    标签: json node.js angularjs-scope pug mean-stack


    【解决方案1】:

    执行此操作时未定义“angReporting”:

    ng-change="ifChange(angReporting)"
    

    您可以使用“$scope.angReporting”在控制器端获取 ng-model“angReporting”值,因此我建议如下:

    控制器

    $scope.incategory = [
        {
          'reporting':'Incident',
          'content':''
        },
        {
          'reporting':'Ticket',
          'content':''
        }];
    $scope.itemList = [];
      $scope.ifChange=function(){
        $scope.itemList.push($scope.angReporting.reporting);
        for (var i=0; i < $scope.itemList.length; i++){
          if($scope.itemList[i] === 'Ticket'){
            $scope.validate = true;
          }
        }
      };
    

    查看

    Select(ng-model='angReporting' ng-options="r.reporting for r in incategory" ng-change="ifChange()" )
    br
    a.btn.btn-primary.btn-sm(ng-click="incidentsCreate()" ng-show="validate") Submit
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-19
      • 1970-01-01
      • 2015-05-26
      • 1970-01-01
      • 1970-01-01
      • 2020-03-31
      • 2020-09-11
      • 2019-04-06
      相关资源
      最近更新 更多