简体   繁体   English

在计算方法 vuejs 中创建一个对象数组?

[英]create an array of objects in the computed method vuejs?

I already appreciate your advice and answers, this time I go to you for the next problem I pass context, I want to create a dynamic table with quasar and vueJS this table will change according to a select field I have managed to bring the columns of the Selected tables, what I can't do is paint them in the view, since for this I must generate the following structure to be able to paint the table:我已经感谢您的建议和回答,这次我将 go 交给您,以解决我传递上下文的下一个问题,我想使用 quasar 和 vueJS 创建一个动态表,该表将根据 select 字段更改,我已设法将列选定的表格,我不能做的是在视图中绘制它们,因为为此我必须生成以下结构才能绘制表格:

 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'
         }
       ]
     }

I want to form the structure above from an array that comes to me from the database (the columns of the table), what I receive is the following:我想从数据库(表的列)提供给我的数组形成上面的结构,我收到以下内容:

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

I am trying as follows in my computed method: My computed method to generate the array of objects The result of this is not what was expected since in each key of my object the entire array is entered in this way.我在我的计算方法中尝试如下:我的计算方法来生成对象数组这不是预期的结果,因为在我的 object 的每个键中,整个数组都是以这种方式输入的。 colums in the image The variable colums is where I want to generate the array of objects described at the beginning of the question.图像中的列 变量列是我想要生成问题开头描述的对象数组的地方。 I appreciate your answers and opinions, anything would help me a lot, thank you very much.感谢您的回答和意见,任何事情都会对我有很大帮助,非常感谢。

Maybe something like following snippet:可能类似于以下代码段:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM