網站搜尋

javascript - 如何使用 Typescript 根據使用者輸入從資料庫取得值


我需要根據使用者輸入從資料庫獲取值。請參閱下面的資料庫快照。

我的前端有一個下拉選單,用來顯示資料庫中的(名稱),我需要根據我在前端選擇的分類來取得資料夾。這是我在 TypeScript 中嘗試過的:

    loadResourceCategory() {
      this.categories = new Array<ResourceCategory>();
      this.isLoading = true;

      return this.resourceService.getResources()
        .then((categories: Array<ResourceCategory>) => {
          this.categories = categories;
          this.categories.forEach((category: any) => {
            category.details = `${category.Name}`;
            this.selectedCategory = category.Id;

            if (category.Id === this.selectedCategory) {
              this.foldername = category.Folder;
              console.log('Selected Category folder is :', + this.foldername);
            }
          });
        })
        .catch(() => {
          this.modalService.error('Resources cannot be loaded now, Please retry later');
        })
        .finally(() => {
          this.isLoading = false;
        });
    }

目前我可以獲取我從下拉選單中選擇的名稱的 ID。我無法獲取資料夾。我該如何解決這個問題?請幫忙!!

答案#1

已解決!! 只要移除「+」就解決了這個問題。console.log('Selected Category folder is :', + this.foldername);