【问题标题】:create an array of objects in the computed method vuejs?在计算方法 vuejs 中创建一个对象数组?
【发布时间】:2022-01-17 03:51:53
【问题描述】:

我已经很感谢你的建议和回答了,这次我去找你解决下一个问题,我通过上下文,我想用 quasar 和 vueJS 创建一个动态表,这个表将根据我设法带来的选择字段而改变选定表的列,我不能在视图中绘制它们,因为为此我必须生成以下结构才能绘制表:

 columns: [
         {
           name: 'id', align: 'center', label: 'id', field: 'id'
         },
         {
           name: 'name', align: 'center', label: 'name', field: 'name'
         },
         {
           name: 'age', align: 'center', label: 'age', field: 'age'
         }
       ]
     }

我想从数据库中得到的一个数组(表的列)形成上面的结构,我收到以下内容:

const columnsTable = [
   "id",
   "name",
   "age"
];

我在我的计算方法中尝试如下: My computed method to generate the array of objects 这不是预期的结果,因为在我的对象的每个键中,整个数组都是以这种方式输入的。 colums in the image 变量列是我想生成问题开头描述的对象数组的地方。 感谢您的回答和意见,任何事情都会对我有很大帮助,非常感谢。

【问题讨论】:

    标签: javascript arrays vuejs2 quasar-framework


    【解决方案1】:

    可能类似于以下 sn-p:

    const columnsTable = [
       "id",
       "name",
       "age"
    ];
    const res = []
    columnsTable.forEach(c => {
      res.push({name: c, align: 'center', label: c, field: c})
    })
    console.log(res)

    【讨论】:

      猜你喜欢
      • 2019-03-31
      • 2016-03-20
      • 2021-05-04
      • 2022-01-21
      • 2023-03-07
      • 1970-01-01
      • 1970-01-01
      • 2019-06-28
      • 1970-01-01
      相关资源
      最近更新 更多