仅在表中打印固有数据

发布于 2025-02-04 16:46:19 字数 5188 浏览 1 评论 0原文

大家好,这是我的个人资料和个人资料详细信息TS和HTML页面。个人资料效果很好,并打印我想要的一切。个人资料详细信息打印来自Supabase的所有数据。我只想将每个测试的所有答案分开。 很多

事情

  
  profile: Profile | undefined;
  userProfile: Profile | undefined;
  validateForm!: FormGroup;
  value?: string;
  isLoadingOne = false;
  profileId: [] = [];
  id_profile: any;


  @Input() session: Session | undefined;

  result: Result []= [];

  answer!: string;
  public parameterValue!: number;

  constructor(private readonly supabase: SupabaseUserService, private router: Router, private fb: FormBuilder,private supabaseQuiz: SupabaseQuizService, private activatedRoute: ActivatedRoute) { }

  session2 = this.supabase.session;


  ngOnInit() {
    this.supabase.authChanges((_, session) => this.session2 = session);
    this.getProfile();
    this.supabaseQuiz.getResult().subscribe((res: Result[]) => {
      let resultIdAns = res
      this.result = resultIdAns
      
    })
    
    //passare category id
    this.supabase.profile.then(profile => {
      if(profile.data){
        this.userProfile = profile.data
       
      }else{
        // this.router.navigateByUrl('account/addProfile')
      }
    })

  }

  async getProfile() {
    try {
      let { data: profile, error, status } = await this.supabase.profile;
      if (error && status !== 406) {
        throw error;
      }
      if (profile) {
        this.profile = profile;
        this.validateForm = this.fb.group({
          username: [this.profile?.username ? this.profile.username : '', [Validators.required]],
          role: [{value: this.profile?.role ? this.profile.role : 'USER', disabled: true}, [Validators.required]],
          website: [this.profile?.website ? this.profile.website: ''],
          avatar_url: [this.profile?.avatar_url ? this.profile.avatar_url: ''],
          email: [this.profile?.email ? this.profile.email : '', [Validators.required]],
        });
      }
    } catch (error: any) {
      alert(error.message)
    }

  }

  async signOut() {
    await this.supabase.signOut();
    this.router.navigateByUrl('account/login')
  }

  submitForm(): void {
    if (this.validateForm.valid) {
      this.isLoadingOne = true;
      try {
        this.supabase.updateProfile(this.validateForm.value).subscribe(res => {
          this.isLoadingOne = false;
        });
      } catch (error: any) {
        this.isLoadingOne = false;
        alert(error.message);
      } 
    } else {
      Object.values(this.validateForm.controls).forEach(control => {
        if (control.invalid) {
          control.markAsDirty();
          control.updateValueAndValidity({ onlySelf: true });
        }
      });
    }
  }
  goToDetail(id: any){
    id = this.session2?.user?.email
    this.router.navigate(['account/user',id]);
  }

}

尝试


  <hr>
  <br>
  <nz-table #headerTable [nzData]="result" [nzPageSize]="50" [nzScroll]="{ y: '240px' }">
    <thead>
      <tr>
        <th>Categoria</th>
        <th>Data</th>
        <th>Risposte corrette</th>
        <th>Punteggio finale</th>
        <th>Action</th>

      </tr>
    </thead>
  
    <tbody>
      
      
      <ng-container *ngFor="let res of result">
        <tr *ngIf="userProfile?.id === res.id_profile">
        
        <td>{{ res.categoryTitle }}</td>
        <td>{{ res.date }}</td>
        <td>{{ res.rightAnswer }}</td>
        <td>{{ res.finalScore }}</td>
        
        <button nz-button nzType="primary" success (click)="goToDetail(parameterValue)">Dettagli</button>

        <!--<td>{{ res.json_answer }}</td>-->
        </tr>
        
      </ng-container>
    
    </tbody>
  
  </nz-table>

  ngOnInit(): void {
    this.supabase.getDetails().subscribe((res: Details[]) => {
      let resultIdAns = res
      this.det = resultIdAns;

    })

    this.supabase.getResult().subscribe((res: Result[]) => {
      let result = res
      this.result = result;

    })

    this.supabaseUser.profile.then(profile => {
      if(profile.data){
        this.userProfile = profile.data
      }});


      this.supabase.getCategories().subscribe(res => {
        this.quizCategories = res;
        
      })
    }
    }

<nz-table #basicTable >
    <thead>
        <tr>
          <th>Categoria</th>
          <th>Question</th>
          <th>Answer</th>
          <th>Date</th>
        </tr>
    </thead>
    <tbody>
      <ng-container *ngFor="let d of det">
        <ng-container>
        <tr *ngIf="userProfile?.id === d.id_profile"> 
        <td>{{d.category_id}}</td>
        <td>{{d.question}}</td>
        <td>{{d.json_answer}}</td>
        <td>{{d.date}}</td>
      </tr>
      </ng-container>
      </ng-container>
    </tbody>
  </nz-table>

hi guys this is my profile and profile details ts and html pages. Profile works quite good and print all I want. Profile detail print all the data from supabase. I just want to divide all the answers for each test not all. I've tried a lot of things but none of them worked

profile TS

  
  profile: Profile | undefined;
  userProfile: Profile | undefined;
  validateForm!: FormGroup;
  value?: string;
  isLoadingOne = false;
  profileId: [] = [];
  id_profile: any;


  @Input() session: Session | undefined;

  result: Result []= [];

  answer!: string;
  public parameterValue!: number;

  constructor(private readonly supabase: SupabaseUserService, private router: Router, private fb: FormBuilder,private supabaseQuiz: SupabaseQuizService, private activatedRoute: ActivatedRoute) { }

  session2 = this.supabase.session;


  ngOnInit() {
    this.supabase.authChanges((_, session) => this.session2 = session);
    this.getProfile();
    this.supabaseQuiz.getResult().subscribe((res: Result[]) => {
      let resultIdAns = res
      this.result = resultIdAns
      
    })
    
    //passare category id
    this.supabase.profile.then(profile => {
      if(profile.data){
        this.userProfile = profile.data
       
      }else{
        // this.router.navigateByUrl('account/addProfile')
      }
    })

  }

  async getProfile() {
    try {
      let { data: profile, error, status } = await this.supabase.profile;
      if (error && status !== 406) {
        throw error;
      }
      if (profile) {
        this.profile = profile;
        this.validateForm = this.fb.group({
          username: [this.profile?.username ? this.profile.username : '', [Validators.required]],
          role: [{value: this.profile?.role ? this.profile.role : 'USER', disabled: true}, [Validators.required]],
          website: [this.profile?.website ? this.profile.website: ''],
          avatar_url: [this.profile?.avatar_url ? this.profile.avatar_url: ''],
          email: [this.profile?.email ? this.profile.email : '', [Validators.required]],
        });
      }
    } catch (error: any) {
      alert(error.message)
    }

  }

  async signOut() {
    await this.supabase.signOut();
    this.router.navigateByUrl('account/login')
  }

  submitForm(): void {
    if (this.validateForm.valid) {
      this.isLoadingOne = true;
      try {
        this.supabase.updateProfile(this.validateForm.value).subscribe(res => {
          this.isLoadingOne = false;
        });
      } catch (error: any) {
        this.isLoadingOne = false;
        alert(error.message);
      } 
    } else {
      Object.values(this.validateForm.controls).forEach(control => {
        if (control.invalid) {
          control.markAsDirty();
          control.updateValueAndValidity({ onlySelf: true });
        }
      });
    }
  }
  goToDetail(id: any){
    id = this.session2?.user?.email
    this.router.navigate(['account/user',id]);
  }

}

Half profile HTML


  <hr>
  <br>
  <nz-table #headerTable [nzData]="result" [nzPageSize]="50" [nzScroll]="{ y: '240px' }">
    <thead>
      <tr>
        <th>Categoria</th>
        <th>Data</th>
        <th>Risposte corrette</th>
        <th>Punteggio finale</th>
        <th>Action</th>

      </tr>
    </thead>
  
    <tbody>
      
      
      <ng-container *ngFor="let res of result">
        <tr *ngIf="userProfile?.id === res.id_profile">
        
        <td>{{ res.categoryTitle }}</td>
        <td>{{ res.date }}</td>
        <td>{{ res.rightAnswer }}</td>
        <td>{{ res.finalScore }}</td>
        
        <button nz-button nzType="primary" success (click)="goToDetail(parameterValue)">Dettagli</button>

        <!--<td>{{ res.json_answer }}</td>-->
        </tr>
        
      </ng-container>
    
    </tbody>
  
  </nz-table>

profile-detail ts

  ngOnInit(): void {
    this.supabase.getDetails().subscribe((res: Details[]) => {
      let resultIdAns = res
      this.det = resultIdAns;

    })

    this.supabase.getResult().subscribe((res: Result[]) => {
      let result = res
      this.result = result;

    })

    this.supabaseUser.profile.then(profile => {
      if(profile.data){
        this.userProfile = profile.data
      }});


      this.supabase.getCategories().subscribe(res => {
        this.quizCategories = res;
        
      })
    }
    }

profile-detail HMTL

<nz-table #basicTable >
    <thead>
        <tr>
          <th>Categoria</th>
          <th>Question</th>
          <th>Answer</th>
          <th>Date</th>
        </tr>
    </thead>
    <tbody>
      <ng-container *ngFor="let d of det">
        <ng-container>
        <tr *ngIf="userProfile?.id === d.id_profile"> 
        <td>{{d.category_id}}</td>
        <td>{{d.question}}</td>
        <td>{{d.json_answer}}</td>
        <td>{{d.date}}</td>
      </tr>
      </ng-container>
      </ng-container>
    </tbody>
  </nz-table>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文