【发布时间】:2021-05-15 12:03:29
【问题描述】:
这是我生成数据以创建 Treeview 时的代码:
import { Injectable } from '@angular/core';
export class Product {
id: string;
text: string;
expanded?: boolean;
items?: Product[];
price?: number;
image?: string;
}
我在 Angular 中这样创建数据:
var products: Product[] = [{
id: "1",
text: "Stores",
expanded: true,
items: [{
id: "1_1",
text: "Super Mart of the West",
expanded: true,
items: [{
id: "1_1_1",
text: "Video Players",
items: [{
id: "1_1_1_1",
text: "HD Video Player",
price: 220,
image: "images/products/1.png"
}, {
id: "1_1_1_2",
text: "SuperHD Video Player",
image: "images/products/2.png",
price: 270
}]
}, {
id: "1_1_2",
text: "Televisions",
expanded: true,
items: [{
id: "1_1_2_1",
text: "SuperLCD 42",
image: "images/products/7.png",
price: 1200
}, {
id: "1_1_2_2",
text: "SuperLED 42",
image: "images/products/5.png",
price: 1450
}
...
}]
}
这是我在 Angular 中运行的输出:
而且我不想用这种方式来设置数据。我可以通过 localhost Web API(从 ASP.NET Core 创建)获取数据吗?
感谢您的所有帮助。我只是一个使用 Angular 的新手(如果我的问题很愚蠢,请原谅我)!!
【问题讨论】:
-
Angular 文档中有一节介绍使用
HttpClient使用后端服务。
标签: c# angular asp.net-core-webapi