배열을 만들어 파멸의 중첩체

0

질문

이 필요를 만들의 배열 id:'s 내 entity: 변수 내에 중첩 stakes 변수에체 proposal. 내가 사용하는 경우 이 코드를 destructure 개체:

const {
   stakes: {
      entity: { id: SupportersId },
    },
 } = proposal
  console.log(SupportersId)

오류를 얻을: TypeError: Cannot read property 'id' of undefined

이것은`말뚝'변수 예제에서 중첩 제안은 개체는 나를 적용하는 코드는 실행의 출력:

const {stakes} = proposal
console.log(stakes)

출력:

0: 
 amount: BigNumber 
    c: [100000] 
    e: 19 
    s: 1 
    __proto__: Object 
 createdAt: 1616006864000 
 entity: {id: "0x60893...734",
        __typename: "Supporter"} 
 id: "appAddress:0x8blahblah...entity:0x608same" 
 proposal: null 
 type: "Add" 

실행하는 경우:

const {stakes: {entity}, }= proposal 
console.log(entity)

을 얻을:

4 Undefined
10 Undefined
10 Undefined
...

이것은 하나의 반복 console.log(JSON.stringify(proposal))

{"id":"28","number":"28",
    "creator":"0x6089368594bf2d3734",
    "status":"Disputed","createdAt":1621957554000,
    "executedAt":0,"metadata":"test","link":"https://",
"stakes":[{"amount":"658768115942029002",
    "createdAt":1626278001000,
    "entity":{"id":"0x80db3372988d852a"},
    "id":"appAddress:0x0ccdedf21399-proposalId:0x1c- 
          entity:0x80db3aeb089372988d852a",
    "type":"Withdraw","proposal":null}],
"stakesHistory":[{"conviction":"0","createdAt":1622175449000,
    "entity":{"id":"0x80db3a571952988d852a"},
    "id":"appAddress:0x0cca32354b5da7dedf21399-proposalId:0x1c- 
          entity:0x80db3a571372988d852a-time:8662647",
"time":"8662647","tokensStaked":"86275362318840579720",
"totalTokensStaked":"86275362318840579720","type":"Add","proposal":null},
{"conviction":"2.156363897696420943854e+21",
"createdAt":1622175824000,"entity":{"id":"0x80db3a5719988d852a"},
"id":"appAddress:0x0ccda7dedf21399-proposalId:0x1c-entity:0x80db3a5b089372988d852a-time:8662672","time":"8662672","tokensStaked":"86202898550724637692",
"totalTokensStaked":"86202898550724637692","type":"Withdraw",
"proposal":null},{"conviction":"3.8533152129053758738146e+22",
"createdAt":1622182185000,
"entity":{"id":"0x80db3a57
2988d852a"},
"id":"appAddress:0x0cc6f0962b415
f21399-proposalId:0x1c-entity:0x80db3a5
72988d852a-time:8663096","time":"8663096","tokensStaked":"84202898550724637692",
"totalTokensStaked":"84202898550724637692","type":"Withdraw",
"proposal":null},{"conviction":"1.114296303522575335279954e+24",
"createdAt":1622406093000,"entity":{"id":"0x80db3a57195616eb3ccbb2b6eb089372988d852a"},"id":"appAddress:0x0cc6
1399-proposalId:0x1c-entity:0x80d
089372988d852a-time:8678021","time":"8678021","tokensStaked":"64202898550724637692",
"totalTokensStaked":"64202898550724637692","type":"Withdraw",
"proposal":null},{"conviction":"1.1372042
9e+24","createdAt":1622414360000,"entity":{"id":"0x80db3a
852a"},"id":"appAddress:0x0cc6
dedf21399-proposalId:0x1c-entity:0x80db3a
852a-time:8678572","time":"8678572","tokensStaked":"4202
37692","totalTokensStaked":"4202898550724637692","type":"Withdraw",
"proposal":null},{"conviction":"1.056
011e+24","createdAt":1622481968000,"entity":{"id":"0x8
2988d852a"},"id":"appAddress:0x0cc6
21399-proposalId:0x1c-entity:0x80
372988d852a-time:8683078","time":"8683078","tokensStaked":"2202898550724637692",
"totalTokensStaked":"2202898550724637692","type":"Withdraw","proposal":null},
{"conviction":"2.91692914179098548409009e+23","createdAt":1623713056000,"entity":{"id":"0x80db3a5
d852a"},"id":"appAddress:0x0cc
df21399-proposalId:0x1c-entity:0x80db3a57
8d852a-time:8765118","time":"8765118","tokensStaked":"2180833333333333347",
"totalTokensStaked":"2180833333333333347","type":"Withdraw","proposal":null},
{"conviction":"1.14417968316260986028367e+23","createdAt":1626276470000,"entity":{"id":"0x80d
8d852a"},"id":"appAddress:0x0cc6f0
f21399-proposalId:0x1c-entity:0x80db3
8d852a-time:8935883","time":"8935883","tokensStaked":"680833333333333347",
"totalTokensStaked":"680833333333333347","type":"Withdraw","proposal":null},
{"conviction":"1.14253001105365595015519e+23","createdAt":1626278001000,"entity":{"id":"0x80db3a57195616eb3ccbb2b6eb089372988d852a"},"id":"appAddress:0x0c
1399-proposalId:0x1c-entity:0x80d
d852a-time:8935985","time":"8935985","tokensStaked":"658768115942029002",
"totalTokensStaked":"658768115942029002","type":"Withdraw","proposal":null},
{"conviction":"3.2774663072910697629524e+22","createdAt":1636282624000,
"entity":{"id":"0x74b232255dc
5951d"},"id":"appAddress:0x0c
1399-proposalId:0x1c-entity:0x74b2
375951d-time:9600096","time":"9600096","tokensStaked":"1000000000000000000",
"totalTokensStaked":"1658768115942029002","type":"Add","proposal":null},
{"conviction":"3.3231555602660371350587e+22","createdAt":1636289513000,"entity":{"id":"0x74b232255
51d"},"id":"appAddress:0x
21399-proposalId:0x1c-entity:0x74b2
75951d-time:9600555","time":"9600555","tokensStaked":"0",
"totalTokensStaked":"658768115942029002","type":"Withdraw","proposal":null}],"beneficiary":"0x000000
000","requestedAmount":"0","totalTokensStaked":"658768115942029002",
"stable":false,"setting":null,"startDate":null,"totalPower":null,
"snapshotBlock":"0","yeas":null,"nays":null,"quietEndingExtensionDuration":null,
"quietEndingSnapshotSupport":null,"script":null,"isAccepted":null,
"casts":[],"actionId":"30","challengeId":"17","challenger":"0xc
020c","challengeEndDate":1622295426000,"disputeId":"10","settledAt":0,
"settlementOffer":"100000000000000000","disputedAt":1622036751000,
"pausedAt":1622036226000,"pauseDuration":0,"collateralRequirement":{"id":"appAddress:0x0cc6f
1399-proposalId:0x1c","proposalId":"appAddress:0x0cc6f
edf21399-proposalId:0x1c","tokenId":"0x3050
a4f9","tokenDecimals":18,"tokenSymbol":"HNYT","actionAmount":"100000000000000000",
"challengeAmount":"100000000000000000","challengeDuration":"259200"},
"submitterArbitratorFee":null,"challengerArbitratorFee":null,"name":"test",
"convictionTrend":"-2.248532625135e-8","currentConviction":"3.28405338806e+22",
"futureConviction":"3.2774+22","futureStakedConviction":"0.00010213206901472402",
"hasEnded":false,"maxConviction":"3.2090344832144279e+26",
"stakedConviction":"0.0001023377406715919","statusData":{"disputed":true},"userConviction":"0","userStakedConviction":"0","requestedAmountConverted":"0"}

희망이 사람이 나를 도울 수 있습니다. 나 같은 느낌을 추가할 필요가 지수 번호 변수에서는 방법을 때 매핑을 통해 배열 요소를 만들지만,나는 또한 특정하지 않에 무엇이 보이는 것처럼,하나도 같은 지역에 있습니다.더 보기 궁극적으로 나가는 전달이 이 목록으로 아동을 또 다른 기능이 지도에서 그것을 통해 또 다른 형태에서 내 응용 프로그램을 끌어 이미지 프로파일에서 데이터의 id 를 만들기를"개인 카"는 경우에는 도움이 됩니다. 모든 도움이나 조언이 크게 감사하겠습니다 감사합니다!

1

최고의 응답

1

여기에는 예 destructures 습니다. 이 예에서 나는 destructure 첫 단체 proposal.stakes array(예:: proposal.stakes[0]).

const proposal = {
    stakes: [{
        amount: 10n,
        c: [100000],
        e: 19,
        s: 1,
        createdAt: 1616006864000,
        entity: {
            id: "0x60893...734",
            __typename: "Supporter"
        },
        id: "appAddress:0x8blahblah...entity:0x608same",
        proposal: null,
        type: "Add",
    }]
};

const {
    stakes: [{
        entity: { id: SupportersId },
    }],
} = proposal;
console.log(SupportersId)

const {stakes: [{entity}], }= proposal;
console.log(entity);

2021-11-24 05:17:45

제안서 객체는 뭔가가 나는 전달에서 수 있습니다. 나를 만들려는 SupportersId 변수를 지도를 통해서 나중에는 응용 프로그램에서 다른 구성 요소입니다.
Striker

@스트라이커,업데이트 내 게시물을 맞는다는 사실 h stakes 시설의 배열을 개체입니다.
Wyck

Wyck,당신은 남자! 감사합니다 너무 많은 보여주는 내게 내가 누락되었습니다. 감사 당신은 노력하고 지식! 환호
Striker

@스트라이커,나는 의견을 주셔서 감사합니다! 클릭할 수 있습니다 표시를 받아들이 대답하는,일반적인 방법으로 우리가 말한"당신이"사람을 스택에서 오버플로우가 발생합니다. ;)
Wyck

많은 제한된 함수에 대한 새로운 사용자 @-사용자 클릭하면을 확인합니다. 하지만 했다는 말했다,그래서 그렇게 했어:)
Striker

다른 언어로

이 페이지는 다른 언어로되어 있습니다

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................