代码之家  ›  专栏  ›  技术社区  ›  Marco Aurélio

javascript中的条件问题

  •  2
  • Marco Aurélio  · 技术社区  · 7 年前

    有人能帮忙吗?我创建了一个选项卡步骤组件,但在进入下一步时遇到了问题,我创建了一个方法,用于单击下一步的“下一步”按钮,但它会忽略条件并进入最后一步。我的代码:

    喂,有人能帮忙吗?我创建了一个选项卡步骤组件,但在进入下一步时遇到了问题,我创建了一个方法,用于单击下一步的“下一步”按钮,但它会忽略条件并进入最后一步。我的代码:

    verifyTabsCoherency(){
            this.enabledTabs = [];
     
    
            this.enabledTabs.push( 
                { title:  this.tabstepItem[0].title , icon: this.tabstepItem[0].icon, content: this.tabstepItem[0].icon, enable: this.tabstepItem[1].enable = true, selected: this.tabstepItem[1].enable = true }
            );
            
            this.enabledTabs.push(
                { title:  this.tabstepItem[1].title, icon: this.tabstepItem[1].icon, content: this.tabstepItem[1].content, enable: this.tabstepItem[1].enable, selected: this.tabstepItem[1].selected  }
            );
    
            if(this.customFilter.enableStation){
                this.enabledTabs.push(
                    { title:  this.tabstepItem[2].title, icon: this.tabstepItem[2].icon, content: this.tabstepItem[2].content, enable: this.tabstepItem[2].enable, selected: this.tabstepItem[2].selected  }
                );
            }
    
            if(this.customFilter.enableUser) {
                this.enabledTabs.push(
                    { title:  this.tabstepItem[3].title, icon: this.tabstepItem[3].icon, content: this.tabstepItem[3].content, enable: this.tabstepItem[3].enable, selected: this.tabstepItem[3].selected  }
                );
            }
    
            if(this.customFilter.enableAccess){
                this.enabledTabs.push(
                    { title:  this.tabstepItem[3].title, icon: this.tabstepItem[4].icon, content: this.tabstepItem[4].content, enable: this.tabstepItem[4].enable, selected: this.tabstepItem[4].selected  }
                );
            }
    
            if(this.customFilter.Companys){
                this.enabledTabs.push(
                    { title:  this.tabstepItem[3].title, icon: this.tabstepItem[5].icon, content: this.tabstepItem[5].content, enable: this.tabstepItem[5].enable, selected: this.tabstepItem[5].selected  }
                );
            }
    
            if(this.customFilter.Customers){
                this.enabledTabs.push(
                    { title:  this.tabstepItem[3].title, icon: this.tabstepItem[6].icon, content: this.tabstepItem[6].content, enable: this.tabstepItem[6].enable, selected: this.tabstepItem[6].selected  }
                )
            }
    
            if(this.customFilter.Sections){
                this.enabledTabs.push(
                    { title:  this.tabstepItem[7].title, icon: this.tabstepItem[7].icon, content: this.tabstepItem[7].content, enable: this.tabstepItem[7].enable, selected: this.tabstepItem[7].selected  }
                )
            }
            
           resolveDate() {
            const myDateStart = new Date(this.dateStart);
            const myDateEnd = new Date(this.dateEnd);
            const myDateStartCompare = new Date(this.dateStartCompare);
            const myDateEndCompare = new Date(this.dateEndCompare);
    
            if ( this.dateStart && this.dateEnd ) {
                    return true;
                } else { return false;}
        }   
        
        resolveCarpark(){
            const mycar = this.car.filter(car => car.checked === true);
            
            if( mycar.length > 0 || this.selectedGroupsTree.length > 0){
                return true;
            }
            else{ return false; }
        }
    
        resolveStations(){
            const myStation = this.stations.filter(stations => stations.checked === true);
    
            if( myStation.length > 0 ){
                return true;
            }
            else{ return false; }
        }
        
          resolveTabItem ( indexTo: number, validateTo: boolean ) {
            this.enabledTabs[indexTo].enable = validateTo;
            this.enabledTabs[indexTo].selected = validateTo;
        }
        
         nextTab(){
          
            if ( this.resolveDate() ) {
                this.resolveTabItem(1, true);
            } else if  ( this.resolveCarpark() ) {
                this.resolveTabItem(2, true);
            }
            }
            
        
            
    1 回复  |  直到 7 年前
        1
  •  1
  •   Desmond    7 年前

    您需要实现某种基于索引的系统来告诉您的逻辑它应该停在哪个选项卡上。

    然后,您将传入索引以导航到下一个选项卡。。nextTab(0)启用第一个选项卡,nextTab(1)启用第二个选项卡。。。

    nextTab(index){
    
            if ( this.resolveDate() && index==0) {
                this.resolveTabItem(1, true);
    
            } else if  ( this.resolveCarpark() && index==1) {
                this.resolveTabItem(2, true);
    
            }
    }