我有一組資料,其中資料的關鍵是不可預測的。我正在嘗試讀取嵌套物件,但似乎無法訪問它,因此我可以檢查下一個鍵Physicians或NonPhysicians. 我嘗試使用嵌套值的鍵來訪問它,但它只回傳未定義。當我退出時,item我得到了預期值,當我退出時,org我得到了物件上的鍵,所以我不確定這里出了什么問題。
const NEWRATES = {
standard: [
{
"ORG A": {
Physicians: {
telehealth: {
weekdayEncounters: 15,
weeknightEncounters: 16.25,
weekendDayEncounters: 16.25,
weekendNightEncounters: 17.25,
holidayEncounters: 17.25,
stipend: 0,
},
},
NonPhysicians: {
telehealth: {
orgName: "Standard",
weekdayEncounters: 15,
weeknightEncounters: 16.25,
weekendDayEncounters: 16.25,
weekendNightEncounters: 17.25,
holidayEncounters: 17.25,
stipend: 0,
},
},
date: "07-2021",
orgName: "some org",
ltc: false,
},
},
{
"ORG B": {
Physicians: {
telehealth: {
weekdayEncounters: 15,
weeknightEncounters: 16.25,
weekendDayEncounters: 16.25,
weekendNightEncounters: 17.25,
holidayEncounters: 17.25,
stipend: 0,
},
},
NonPhysicians: {
telehealth: {
orgName: "Standard",
weekdayEncounters: 15,
weeknightEncounters: 16.25,
weekendDayEncounters: 16.25,
weekendNightEncounters: 17.25,
holidayEncounters: 17.25,
stipend: 0,
},
},
date: "07-2021",
orgName: "some org",
ltc: false,
},
},
],
ltc: [
{
Infinity: {
Physicians: {
associates: {
roundingHours: 10,
onCallHours: 10,
weekdayEncounters: 16,
weeknightEncounters: 17.25,
weekendDayEncounters: 18.25,
weekendNightEncounters: 19.25,
holidayEncounters: 20.25,
stipend: 0,
},
},
NonPhysicians: {
associates: {
roundingHours: 0,
onCallHours: 0,
weekdayEncounters: 15,
weeknightEncounters: 16.25,
weekendDayEncounters: 16.25,
weekendNightEncounters: 17.25,
holidayEncounters: 17.25,
stipend: 0,
},
},
date: "07-2021",
orgName: "some org",
ltc: true,
},
},
],
};
const sortData = Object.values(NEWRATES);
const NEWfiltered = !!NEWRATES && sortData;
const byProviderType =
!!NEWfiltered &&
NEWfiltered.map((item, idx) => {
for (let i = 0; i < item.length; i ) {
let list = [];
let org = Object.keys(item[i]).toString();
console.log(item[org]);
}
});
uj5u.com熱心網友回復:
你很近。你需要繼續深入一層。
// Your Code Now
console.log(item[org]);
// SHOULD BE
console.log(item[i][org]);
進行此更新,您將看到它正在運行。這里是stackblitz 上的一個作業版本。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/336798.html
標籤:javascript 循环 目的 嵌套对象
上一篇:物件屬性的值未按預期更改
