angular12 - 带有 CountryName 的 Angular CityList
问题描述
在我的I have cities with
id and
name and
counteyid and countries with
id and
name how to iterate this
response.value to 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,
}))
);
推荐阅读
- python - 抓取 Div 类 HTML 时如何在 For 循环中嵌套 If 语句
- php - 即使使用“代理授权:基本”,PHP 也无法使用代理进行身份验证
- mysql - 我有可能找到一行包含一个字符串吗?假设我不知道哪些列包含字符串
- php - in_array 的选项值不起作用
- c# - DbContext 在使用异步任务方法时被释放
- sql - PL/SQL [忽略 SQL 语句]
- python - 我应该如何在线性回归中拟合我的曲线?:张量流
- apache-kafka - kafka Burrow 报告相同 consumer_group 和相同主题的多个偏移量
- marklogic - 使用数据中心中的文档值进行选择性协调
- c++ - 这个 C++ 宏有什么作用(竞争性编程)?