Json嵌套数据循环

时间:2019-04-25 08:00:03

标签: javascript reactjs loops

我有列表ob数组json对象,我试图建立循环,但我无法 该对象仍然为空,我试图使用嵌套地图来渲染数据是正确的,请给我帮助以渲染该对象, 三个子数组,或多或少

let d= [
    [
     
      {
         "suit":"♥︎",
         "val":"Q"
      },
      
      {
         "suit":"♠︎",
         "val":"9"
      },
      {
         "suit":"♣︎",
         "val":"6"
      },
      {
         "suit":"♣︎",
         "val":"1"
      },
      {
         "suit":"♠︎",
         "val":"4"
      },
      {
         "suit":"♣︎",
         "val":"2"
      }],
    [
    
      {
         "suit":"♦︎",
         "val":"3"
      },
      {
         "suit":"♥︎",
         "val":"2"
      },
     
      {
         "suit":"♠︎",
         "val":"5"
      }],[
      {
         "suit":"♠︎",
         "val":"2"
      },
      {
         "suit":"♦︎",
         "val":"5"
      },
     
      {
         "suit":"♠︎",
         "val":"3"
      }]];

1 个答案:

答案 0 :(得分:-1)

尝试

let d=[[{"suit":"♥︎","val":"Q"},{"suit":"♠︎","val":"9"},{"suit":"♣︎","val":"6"},
  {"suit":"♣︎","val":"1"},{"suit":"♠︎","val":"4"},{"suit":"♣︎","val":"2"}],
  [{"suit":"♦︎","val":"3"},{"suit":"♥︎","val":"2"},{"suit":"♠︎","val":"5"}],
  [{"suit":"♠︎","val":"2"},{"suit":"♦︎","val":"5"},{"suit":"♠︎","val":"3"}]];

let s= d.map(x=>`<p>${x.map(y=>`<span>${y.val+y.suit}</span>`).join('')}</p>`)

document.body.innerHTML+=s.join('')
span { margin-left: 20px;}