首页 > 解决方案 > 如何在vuejs中拼接嵌套数组

问题描述

我的查询结果

absent: 0
attn: {21: {days: 5}, 22: {days: 5}, 23: {days: 3}}
daily_rate: 57.50798722044728
deduction: {4: {amount: 333.33}, 6: {amount: 222.2, },…}
4: {amount: 333.33,}
6: {amount: 222.2}
7: {amount: 2242}
8: {amount: 1127.5}
9: {amount: 1120}

在我的 vue js 中,我有父数组和子数组..我不知道如何在嵌套数组中拼接数据

                     <tbody>
                    <tr v-for="(fetch, count) in payrollPayableArray">  -----> PARENT ARRAY
                     <td style="height:10px;">{{fetch.pay_class}}</td>
                     <td style="height:10px; color:red;">{{formatNum(fetch.absent * fetch.daily_rate)}}</td>
                     <td style="height:10px; color:red;">{{formatNum(fetch.late * fetch.rate_per_minute)}}</td>
                     <td style="height:10px; color:red;">{{formatNum(fetch.ut * fetch.rate_per_minute)}}</td>
                     <td style="height:10px;">{{formatNum(fetch.gross)}}</td>
                     

                    <template v-for="(disp, index) in fetch.deduction">   --> CHILD ARRAY
                     <td>{{disp.amount}} <button type="button" @click="removeDeduction(index)"class="btn btn-danger btn-sm">X</button> </td>
                     </template>
                   
                    </tr>
                  </tbody>

这个功能不起作用......我希望你能帮助我

   removeDeduction(index) {
          return this.payrollPayableArray.reduce((acc,item)=>{
           const arr =  Object.values(item.deduction).reduce((bcc,a,idx)=>{
            Object.values(idx).splice(index,1)
          
           })
        
           })

           
         },

我的问题类似于此https://jsfiddle.net/uLqfks3e/5/

标签: javascriptarraysvue.js

解决方案


推荐阅读