“找不到ID为ID的列”,但该列在那里

时间:2020-10-16 03:20:40

标签: angular typescript angular-material

我想发生的事情:

我希望供应商ID出现并停止给我一个错误。

正在发生的事情:

我遇到了找不到列错误。


我在客户端使用打字稿,在服务器端使用java(未显示,只是以为我会扔掉它)。我还将Angular框架与Material组件一起使用。


我收到错误错误:找不到ID为“ vendorid”的列,但我的表中存在vendorid。我已经呆了几个小时了,无法弄清为什么它不起作用。


我尝试过的事情:

  • 我已经通过检查localhost来检查我的数据是否正常工作。
  • 如果我从.ts的displayColumns中删除了vendorid,则不会出现任何错误,并且我的数据也会显示出来。
  • 我已通过复制并粘贴所使用的拼写形式来确保拼写正确。

这是我的html的样子:

<mat-card *ngIf="hideEditForm" style="margin-bottom: 10vh;">
  <mat-card-header layout="row">
    <mat-card-title style="margin-bottom: 4vh;">
      <span>{{ msg }}</span>
    </mat-card-title>
  </mat-card-header>
  <mat-card-content>
    <table mat-table [dataSource]="dataSource" class="mat-elevation-z8" matSort>
      <ng-container matColumnDef="id">
        <th mat-header-cell *matHeaderCellDef mat-sort-header><div class="centerheader">Product No.</div></th>
        <td mat-cell *matCellDef="let element"> {{element.id}} </td>
      </ng-container>
      <ng-container matColumnDef="name">
        <th mat-header-cell *matHeaderCellDef mat-sort-header><div class="centerheader">Name</div></th>
        <td mat-cell *matCellDef="let element"> {{element.name}} </td>
      </ng-container>
      <!-- Vendor Id Column -->
      <ng-container matColumnDef="employeeid">
        <th mat-header-cell *matHeaderCellDef mat-sort-header> <div class="centerheader">Vendor No.</div></th>
        <td mat-cell *matCellDef="let element"> {{element.vendorid}} </td>
      </ng-container>
      <tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr>
      <tr mat-row *matRowDef="let row; columns: displayedColumns;"
          (click)="select(row)"></tr>
    </table>
    <div class="padtop15">
      <mat-icon (click)="newProduct()" matTooltip="Add New Product" class="addicon" color="primary" >
        control_point
      </mat-icon>
    </div>
  </mat-card-content>
</mat-card>
<mat-card *ngIf="!hideEditForm">
  <mat-card-header layout="row">
    <mat-card-title><span>{{ msg }}</span></mat-card-title>
  </mat-card-header>
  <mat-card-content>
    <app-product-detail [selectedProduct]="selectedProduct"
                        [vendors]="vendors$ | async"
                        (cancelled)="cancel('cancelled')"
                        (saved)="save($event)"
                        (deleted)="delete($event)">
    </app-product-detail>
  </mat-card-content>
</mat-card>

这是我的.ts的样子:

import {Component, OnInit, ViewChild } from '@angular/core';
import { MatTableDataSource } from '@angular/material/table';
import { MatSort } from '@angular/material/sort';
import { Product } from './product';
import { Vendor } from '../vendor/vendor';
import { VendorService } from '../vendor/vendor.service';
import { ProductService } from '../product/product.service';
import { Observable, of } from 'rxjs';
import { catchError, share } from 'rxjs/operators';
@Component({
  selector: 'app-product',
  templateUrl: 'product-home.component.html'
})
export class ProductHomeComponent implements OnInit {
  vendors$: Observable<Vendor[]>;
  products: Product[];
  products$: Observable<Product[]>;
  selectedProduct: Product;
  hideEditForm: boolean;
  msg: string;
  todo: string;
  url: string;
  displayedColumns: string[] = ['id', 'name', 'vendorid'];
  dataSource: MatTableDataSource<Product>;

  @ViewChild(MatSort) sort: MatSort;
  constructor(private productService: ProductService, private vendorService: VendorService) {
    this.hideEditForm = true;
  } // constructor

  ngOnInit(): void {
    this.msg = 'loading vendors from server...';
    this.msg = `Vendor's loaded`;
    this.vendors$ = this.vendorService.getAll().pipe(
      share(),
      catchError(error => {
        if (error.error instanceof ErrorEvent) {
          this.msg = `Error: ${error.error.message}`;
        } else {
          this.msg = `Error: ${error.message}`;
        }
        return of([]);
      })
    );
    this.msg = `Product's loaded`;
    this.products$ = this.productService.getAll().pipe(
      share(),
      catchError(error => {
        if (error.error instanceof ErrorEvent) {
          this.msg = `Error: ${error.error.message}`;
        } else {
          this.msg = `Error: ${error.message}`;
        }
        return of([]);
      })
    );
    this.refreshDS();
  }
  select(product: Product): void {
    this.todo = 'update';
    this.selectedProduct = product;
    this.msg = `Product ${product.id} selected`;
    this.hideEditForm = !this.hideEditForm;
  } // select
  /**
   * cancelled - event handler for cancel button
   */
  cancel(msg?: string): void {
    this.hideEditForm = !this.hideEditForm;
    this.refreshDS();
  } // cancel
  /**
   * update - send changed update to service update local array
   */
  update(product: Product): void {
    this.msg = 'Updating...';
    this.productService.update(product).subscribe( payload => {
        if (payload.id !== '') {
          this.msg = `Product ${product.id} updated!`;
        } else {
          this.msg = 'Product not updated! - server error';
        }
        this.refreshDS();
      },
      err => {
        this.msg = `Error - product not updated - ${err.status} - ${err.statusText}`;
      });
    this.hideEditForm = !this.hideEditForm;
  } // update
  /**
   * save - determine whether we're doing and add or an update
   */
  save(product: Product): void {
    (product.id) ? this.update(product) : this.add(product);
  } // save
  /**
   * add - send product to service, receive newid back
   */
  add(product: Product): void {
    this.msg = 'Adding...';
    product.id = '';
    this.productService.add(product).subscribe( payload => {
        if (payload.id !== '') {
          this.msg = `Product ${payload.id} added!`;
        } else {
          this.msg = 'Product not added! - server error';
        }
        this.refreshDS();
      },
      err => {
        this.msg = `Error - product not added - ${err.status} - ${err.statusText}`;
      });
    this.hideEditForm = !this.hideEditForm;
  } // add
  /**
   * newProduct - create new product instance
   */
  newProduct(): void {
    this.selectedProduct = {
      id: '',
      vendorid: 0,
      name: '',
      costprice: 0,
      msrp: 0,
      rop: 0,
      eoq: 0,
      qoh: 0,
      qoo: 0,
      qrcode: '',
      qrcodetxt: '',
    };
    this.msg = 'New product';
    this.hideEditForm = !this.hideEditForm;
  } // newProduct
  /**
   * delete - send product id to service for deletion
   */
  delete(product: Product): void {
    this.msg = 'Deleting...';
    this.productService.delete_idString(product.id)
      .subscribe(payload => {
          if (payload === '1') { // server returns # rows deleted
            this.msg = `Product ${product.id} deleted!`;
          } else {
            this.msg = 'Product not deleted!';
          }
          this.refreshDS();
        },
        err => {
          this.msg = `Error - product not deleted - ${err.status} - ${err.statusText}`;
        });
    this.hideEditForm = !this.hideEditForm;
  } // delete
  /**
   * refresh - update data table with any changes,
   * and reset sort directive
   */
  refreshDS(): void {
    this.products$.subscribe(products => {
      this.dataSource = new MatTableDataSource(products);
      this.dataSource.sort = this.sort;
    });
  } // refresh
} // ProductHomeComponent

2 个答案:

答案 0 :(得分:2)

我不知道您实际上想做什么,但我遇到了问题。供应商编号的{% extends 'generic.html' %} {% block content %} <div id="main" class="container"> <div class="row 200%"> <div class="6u 12u$(medium)"> <h3>Classifier</h3> <form method="post" action="#"> <div class="row uniform"> <div class="9u 12u$(small)"> <input type="text" name="query_classifier" id="query_classifier" value="" placeholder="Фильтр" /> </div> </div> </form> {# THE NEW CSS CLASS FOR TREE VIEW #} <div class="css-treeview"> <ul> {# CURRENT NESTING LEVEL #} {% set l = 0 %} {# ITERATE ACROSS THE PASSED VARIABLE (LIST) #} {% for item in classifier %} {# INCREASE LEVEL (NEST) #} {% if item['level'] > l %} {% for n in range(item['level'] - l) %}<ul>{% endfor %} <!-- Break --> {# DECREASE LEVEL (UNNEST) #} {% elif item['level'] < l %} {% for n in range(l - item['level']) %}</ul>{% endfor %} <!-- Break --> {% endif %} {# OUTPUT ITEM AS CHECKBOX OR LABEL #} {% if item['id'] == -1 %} <li><label>{{ item['name'] }} [{{ item['count'] }}]</label></li> {% else %} <li><a href="./">{{ item['name'] }}</a></li> {% endif %} {% set l = item['level'] %} {% endfor %} </ul> </div> </div> <div class="6u 12u$(medium)"> <h3>Датасеты</h3> <!-- Break --> <!-- Break --> </div> </div> </div> {% endblock %}应该是供应商编号,而不是员工编号:

matColumnDef

答案 1 :(得分:0)

更改

apiVersion: v1
kind: ConfigMapList
items:
  - apiVersion: v1
    data:
      test: 1
    kind: ConfigMap
    metadata:
      name: grafana-dashboard-apiserver1
      namespace: monitoring
      labels:
        grafana_dashboard: "1"   
  - apiVersion: v1
    data:
      test: 2
    kind: ConfigMap
    metadata:
      name: grafana-dashboard-apiserver2
      namespace: monitoring   
      labels:
        grafana_dashboard: "1" 
  - apiVersion: v1
    data:
      test: 3
    kind: ConfigMap
    metadata:
      name: grafana-dashboard-apiserver3
      namespace: monitoring    
      labels:
        grafana_dashboard: "1" 

  <ng-container matColumnDef="employeeid">