Adhikar Patil

Adhikar Patil

  • 1.6k
  • 434
  • 72.2k

Hello how to iterate on objects in Select.edit.data.js

Apr 20 2020 3:39 AM
Hello,
          I am using formio select component in my angular 8 project. But i am using Data Source Type as URL in Data Tab and in Data Source URL i have given the json path(project.json). Also i have used custom select component to read keys from json in Data Tab. i have used the following  custom select component to read the keys from json file. i have used the following code in Select.edit.data.js
 
{
type: 'select',
input: true,
multiple: true,
label: 'Json Keys',
key: 'jsonKey',
placeholder: 'Select your json key you want to show',
clearOnHide: true,
tooltip: '',
weight: 12,
refreshOn: 'data.url',
clearOnRefresh: true,
dataSrc: 'url',
data: {
url: 'project.json'
},
conditional: {
json: {
'===': [{
var: 'data.dataSrc'
}, 'url']
}
},
template: '<span>{{ Object.keys(item) }}</span>'
},
 
Also i have project.json which contains following data
 
 
 
[
{
"projectid": 100,
"surveytitle": "Parth Infotech Survey",
"surveydescription": "Health Checkup",
"date": "03/30/2020",
"country": "India",
"latitude": "",
"longitude": "",
"survey expiry date": ""
},
{
"projectid": 101,
"surveytitle": "PnAutomation Survey",
"surveydescription": "Health Checkup",
"date": "03/30/2020",
"country": "US",
"latitude": "",
"longitude": "",
"survey expiry date": ""
},
{
"projectid": 103,
"surveytitle": "Parth Survey",
"surveydescription": "Health Checkup",
"date": "03/30/2020",
"country": "China",
"latitude": "",
"longitude": "",
"survey expiry date": ""
}
]
 
 
But i want to bind the unique keys from project.json. So how can i iterate on array of item objects in template. i have used the template field to get the keys from json but not working properly. i have changed in select.edit.data.js
like 
template: '<span>{{ Object.keys(item) }}</span>'
 
 
pleae provide the solution for me to get unique keys from json and bind to custom select component. 
 
 
 
 
 

Answers (1)