简体   繁体   English

如何在打字稿中选择键值[object:object]?

[英]How to select key value [object:object] in typescript?

i want to take pincode from filtered data from object. 我想从对象的过滤数据中获取pincode。 and i want to display in HTML select in angular 我希望以HTML格式显示角度

[ { 
"stateName": "UP", 
"stateCode": "2", 
"pincode": [ { "pin": 555, "dis": "Gazhipur" }, 
         { "pin": 888, "dis": "Agra" } 
       ] 
} ]

i expect for html select 我希望html选择

{
   "pincode": [ 
                {"pin": 555, "dis": "Gazhipur" }, 
                {"pin": 888, "dis": "Agra" } 
              ] 
}

You can map your array of objects like this code and put the result in the select 您可以像这样的代码映射对象数组,并将结果放在select中

let result = states.map(state => {
    return state.pincode
})
// or
let result = states.map(state => state.pincode)

Use Object.assign() and manipulate the data as shown below. 使用Object.assign()并操作数据,如下所示。

 const data = [ { "stateName": "UP", "stateCode": "2", "pincode": [ { "pin": 555, "dis": "Gazhipur" }, { "pin": 888, "dis": "Agra" } ] } ]; const result = data[0].pincode; const expectedResult = Object.assign({}, {"pincode": result}); console.log(expectedResult); 

Your html should look like this. 你的html应该是这样的。

<li *ngFor="let item of expectedResult.pincode"
  <span>{{item.pin}}: {{item.dis}}</span> {{hero.name}}
</li>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM