Angular 带有国家名称的城市列表
Angular CityList With CountryName
在我的I have cities with
idand
nameand
counteyidand countries with
idand
namehow to iterate this
response.valueto get a list having
cityid,name,countryid`?
我猜你可以使用 map 函数,这里有一些代码示例。我像这样扩展你的列表,结果如下所示
const value = [
{
id: "1",
name: "cityname",
countryId: "countryId",
countries: [{ id: 1, name: "countryname" }],
},
{
id: "2",
name: "cityname-2",
countryId: "countryId-2",
countries: [{ id: 2, name: "countryname-2" }],
},
{
id: "3",
name: "cityname-3",
countryId: "countryId-3",
countries: [{ id: 3, name: "countryname-3" }],
},
];
// you can check your list result
console.log(
value.map((m) => ({
cityId: m.id,
cityName: m.name,
countryId: m.countryId,
}))
);
在我的I have cities with
idand
nameand
counteyidand countries with
idand
namehow to iterate this
response.valueto get a list having
cityid,name,countryid`?
我猜你可以使用 map 函数,这里有一些代码示例。我像这样扩展你的列表,结果如下所示
const value = [
{
id: "1",
name: "cityname",
countryId: "countryId",
countries: [{ id: 1, name: "countryname" }],
},
{
id: "2",
name: "cityname-2",
countryId: "countryId-2",
countries: [{ id: 2, name: "countryname-2" }],
},
{
id: "3",
name: "cityname-3",
countryId: "countryId-3",
countries: [{ id: 3, name: "countryname-3" }],
},
];
// you can check your list result
console.log(
value.map((m) => ({
cityId: m.id,
cityName: m.name,
countryId: m.countryId,
}))
);