【发布时间】:2019-02-26 13:18:06
【问题描述】:
component.html
<select data-placeholder="All Categories" class="category" value="category.category.categoryName">
<option selected="selected" style="display:none">Select Category</option>
<option class="select" *ngFor="let category of categories" value="category">
{category.categoryName}}
</option>
</select>
<select data-placeholder="All Cities" class="services location" value="category.categoryName">
<option selected="selected" style="display:none">select type of services</option>
<option *ngFor="let category of selected.categoryServicemodel; let i =
index" value="category">{{category.serviceName}}
</option>
</select>
component.ts
export class Component {
categories: any[];
services: any[];
cities: any[];
selected: any = {};
constructor() {
getAllCategories();
{
this.postService.getAllCategories()
.subscribe(data => {
this.categories = data.json();
console.log(this.categories);
});
}
getAllService();
{
this.postService.getAllServices()
.subscribe(res => {
this.services = res.json();
});
}
}
}
回复
[
{
"categoryId": 1,
"categoryName": "Painting",
"categoryDesc": "Painting of all types",
"categoryServicemodel": [
{
"serviceId": 1,
"serviceName": "Test12",
"serviceDesc": "test12",
"isActive": 1
},
{
"serviceId": 3,
"serviceName": "TESTINGEXAMPLE ",
"serviceDesc": "TESTINGEXAMPLE Details
Information
",
"isActive": 1
},
{
"serviceId": 12,
"serviceName": "New Painters",
"serviceDesc": "office paintings ",
"isActive": 2
},
{
"serviceId": 11,
"serviceName": "ABC Painters",
"serviceDesc": "painting of all types",
"isActive": 1
}
],
"active": 1
},
{
"categoryId": 2,
"categoryName": "string",
"categoryDesc": "string",
"categoryServicemodel": [
{
"serviceId": 2,
"serviceName": "Test15",
"serviceDesc": "test15",
"isActive": 1
}
],
"active": 0
},
{
"categoryId": 4,
"categoryName": "carpenter",
"categoryDesc": "Carpenter",
"categoryServicemodel": [
{
"serviceId": 5,
"serviceName": "Test Carpenter ",
"serviceDesc": "Test carpenter Description",
"isActive": 1
}
],
"active": 0
}
]
我的问题是当我为 ex 选择第一个类别名称时。绘画(在我的回复中)该类别下的所有服务名称都应在第二个下拉列表中更改 如果我再次选择第二个类别,那么该类别下的所有服务名称都应该在第二个下拉列表中可用
【问题讨论】:
-
请缩进您的代码。您的数据结构很棘手。当您选择一个选项时,获取值和
filter服务。但我不认为你能用这种数据结构有效地做到这一点。
标签: angular