how can i listing component nestedly? - reactjs

[
{
"id": 0.5256669517010202,
"color": false,
"selected": false,
"name": "",
"type": "",
"label": "",
"fieldName": "",
"required": "",
"validation": ""
},
{
"id": 0.5901705709044824,
"color": false,
"selected": false,
"type": [
{
"id": 0.30332161644408817,
"color": true,
"selected": false,
"name": "",
"type": "",
"label": "",
"fieldName": "",
"required": "",
"validation": ""
},
{
"id": 0.5423422175390649,
"color": true,
"selected": false,
"name": "",
"type": "",
"label": "",
"fieldName": "",
"required": "",
"validation": ""
},
{
"id": 0.959208393000617,
"color": true,
"selected": false,
"name": "",
"type": "",
"label": "",
"fieldName": "",
"required": "",
"validation": ""
}
],
"label": "",
"fieldName": "",
"required": "",
"validation": ""
},
{
"id": 0.5933110602496239,
"color": false,
"selected": false,
"type": "",
"label": "",
"fieldName": "",
"required": "",
"validation": ""
}
]

I think you should use Map method
const data = [
{
"id": 0.5256669517010202,
"color": false,
"selected": false,
"name": "",
"type": "",
"label": "",
"fieldName": "",
"required": "",
"validation": ""
},
{
"id": 0.5901705709044824,
"color": false,
"selected": false,
"type": [
{
"id": 0.30332161644408817,
"color": true,
"selected": false,
"name": "",
"type": "",
"label": "",
"fieldName": "",
"required": "",
"validation": ""
},
{
"id": 0.5423422175390649,
"color": true,
"selected": false,
"name": "",
"type": "",
"label": "",
"fieldName": "",
"required": "",
"validation": ""
},
{
"id": 0.959208393000617,
"color": true,
"selected": false,
"name": "",
"type": "",
"label": "",
"fieldName": "",
"required": "",
"validation": ""
}
],
"label": "",
"fieldName": "",
"required": "",
"validation": ""
},
{
"id": 0.5933110602496239,
"color": false,
"selected": false,
"type": "",
"label": "",
"fieldName": "",
"required": "",
"validation": ""
}
]
data.map((item) => item.id)

Just Try!
You should declared attribute type as Array always!
data.map(Item => (
Item.type.map(Item => ())
))

the map method is suitable here. For example you have your all data within state or another variable, well you can map throw it:
<div>
{yourData?.length && yourData.map(item => {
return(
<span>{item.id}</span>
...
<div>{item.type.map(typeItem => {
return(
<span>{typeItem.id}</span>
...
)
})
)})}
</div>

Related

node red function add and remove object from context array

I have a for loop in the node red function that a the start of the function I get the array from the context
var alarmArray = flow.get("alarmArray")
and after I need to push object on the array I have do this but I'm not pusching on the flow context array but in the local array
alarmArray.push({
key: "Low air pressure",
value: alarm1Cip
});
flow.set("alarm1CipOld",alarm1Cip);
and after in the for loop I need to remove the object from the context but in my way I remove it from local array
for (var key in alarmArray){
node.warn(key);
msg.payload = {
"title": alarmArray[key].key,
"isActive":alarmArray[key].value
};
node.send(msg)
delete alarmArray[key]
}
how can I manage to add and remove object in the context array?
thanks
The problem here is that NodeJS is a pass by reference language. This means that there are not 2 arrays here, only 1 that has 2 handles (var alarmArray and flow.get('alarmArray'))
This means that anything pushed/deleted on the "local" copy is also getting pushed/deleted to the copy in the context.
The only way to do what you want will be to make a deep copy of the array every time you recover it from the context and then work on the copy locally.
Assuming the array only holds simple objects then the following should work:
var alarmArray = JSON.parse(JSON.stringify(flow.get('alarmArray')))
If you want to save your changes you just have to reload the mutated object in the right context, overwriting the previous value with
flow.set('alarmArray', alarmArray)
You might better to use global.set instead of flow.set
This might help you.
[
{
"id": "133329daaceb6bb3",
"type": "tab",
"label": "flow 3",
"disabled": false,
"info": "",
"env": []
},
{
"id": "c80bec9a15b703f6",
"type": "inject",
"z": "133329daaceb6bb3",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 140,
"y": 140,
"wires": [
[
"8687551e01cd2045"
]
]
},
{
"id": "8687551e01cd2045",
"type": "function",
"z": "133329daaceb6bb3",
"name": "msg_1",
"func": "global.set(\"msg_1\",\"test\");\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 280,
"y": 140,
"wires": [
[]
]
},
{
"id": "103b03c39c8d9cae",
"type": "debug",
"z": "133329daaceb6bb3",
"name": "debug 29",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 500,
"y": 300,
"wires": []
},
{
"id": "c043cba9f34ba574",
"type": "inject",
"z": "133329daaceb6bb3",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 140,
"y": 180,
"wires": [
[
"e674c706437cc0f3"
]
]
},
{
"id": "e674c706437cc0f3",
"type": "function",
"z": "133329daaceb6bb3",
"name": "msg_2 ",
"func": "global.set(\"msg_2\",\"hello\");\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 280,
"y": 180,
"wires": [
[]
]
},
{
"id": "11f8fb75d4c4e6c0",
"type": "inject",
"z": "133329daaceb6bb3",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "1",
"crontab": "",
"once": true,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 150,
"y": 300,
"wires": [
[
"1346e34e8c83b2dc"
]
]
},
{
"id": "1346e34e8c83b2dc",
"type": "function",
"z": "133329daaceb6bb3",
"name": "check if 2 msg set",
"func": "var msg1 = global.get(\"msg_1\");\nvar msg2 = global.get(\"msg_2\");\n\nif(msg1 && msg2){\n msg.payload=\"both message arrived!\";\n}\nelse{\n msg.payload=\"Nope. Not yet.\";\n}\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 330,
"y": 300,
"wires": [
[
"103b03c39c8d9cae"
]
]
},
{
"id": "62d522a844321ef9",
"type": "inject",
"z": "133329daaceb6bb3",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 540,
"y": 140,
"wires": [
[
"6d109daff443dade"
]
]
},
{
"id": "6d109daff443dade",
"type": "function",
"z": "133329daaceb6bb3",
"name": "reset",
"func": "global.set(\"msg_1\",null);\nglobal.set(\"msg_2\",null);\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 690,
"y": 140,
"wires": [
[]
]
},
{
"id": "4e1848c867860d5f",
"type": "comment",
"z": "133329daaceb6bb3",
"name": "Here gonna auto-run",
"info": "",
"x": 170,
"y": 260,
"wires": []
},
{
"id": "3102e176923a8fad",
"type": "comment",
"z": "133329daaceb6bb3",
"name": "Check what if both inject clicked",
"info": "",
"x": 210,
"y": 100,
"wires": []
}
]

Insert parameters into JSON Array in Logic Apps

I am creating a Logic app to gather members from one platform using an API call and posting them to another platform using POST method. At the end of the entire process, I get a JSON array with the data that I need. However, I need to add in a parameters into the array at the beginning. How would I go about doing so?
Currently, my array looks like this
[
{
"company": "",
"email": "",
"firstName": "",
"lastName": "",
"nickname": "",
"prefix": "",
"sourceId": "",
"title": "",
"workPhone": ""
},
{
"company": "",
"email": "",
"firstName": "",
"lastName": "",
"nickname": "",
"prefix": "",
"sourceId": "",
"title": "",
"workPhone": ""
}
]
I need for the body of my HTTP request to look like this:
**{"data":**
[
**"dataRecord":** {
"company": "",
"email": "",
"firstName": "",
"lastName": "",
"nickname": "",
"prefix": "",
"sourceId": "",
"title": "",
"workPhone": ""
},
{
"company": "",
"email": "",
"firstName": "",
"lastName": "",
"nickname": "",
"prefix": "",
"sourceId": "",
"title": "",
"workPhone": ""
}
}
My current flow looks like this:
Scheduled Trigger
List item
Authenticate platform (to)
Authentication platform(from)
Get Data
Compose data
Parse Json
Initialize Array Variable
For Each:
(1)Compose - Map Parsed JSON data to Destination Fields
(2)Append to array variable
compose expression: string(variables('variable'))
Compose string to Json: json(string(outputs('Compose_2')))
HTTP POST
Edit:
Adding screenshot of where I need the data to be in the output, along with what my app looks like
After receiving the json array try using Parse Json action of Data Operations Connector to get the parameters and then you can form a json using Compose Connector. Here is the screenshot of my logic app for your reference.
Here is the output:
Here is the schema in the compose connector
{
"data": [
{
"dataRecord": {
"company": "#{items('For_each')['company']}",
"email": "#{items('For_each')['email']}",
"firstName": "#{items('For_each')['firstName']}",
"lastName": "#{items('For_each')['lastName']}",
"nickname": "#{items('For_each')['nickname']}",
"prefix": "#{items('For_each')['prefix']}",
"sourceId": "#{items('For_each')['sourceId']}",
"title": "#{items('For_each')['title']}",
"workPhone": "#{items('For_each')['workPhone']}"
}
}
]
}
Below is the code view of my logic app
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"For_each": {
"actions": {
"Compose": {
"inputs": {
"data": [
{
"dataRecord": {
"company": "#{items('For_each')['company']}",
"email": "#{items('For_each')['email']}",
"firstName": "#{items('For_each')['firstName']}",
"lastName": "#{items('For_each')['lastName']}",
"nickname": "#{items('For_each')['nickname']}",
"prefix": "#{items('For_each')['prefix']}",
"sourceId": "#{items('For_each')['sourceId']}",
"title": "#{items('For_each')['title']}",
"workPhone": "#{items('For_each')['workPhone']}"
}
}
]
},
"runAfter": {},
"type": "Compose"
}
},
"foreach": "#body('Parse_JSON')",
"runAfter": {
"Parse_JSON": [
"Succeeded"
]
},
"type": "Foreach"
},
"Parse_JSON": {
"inputs": {
"content": "#triggerBody()",
"schema": {
"items": {
"properties": {
"company": {
"type": "string"
},
"email": {
"type": "string"
},
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
},
"nickname": {
"type": "string"
},
"prefix": {
"type": "string"
},
"sourceId": {
"type": "string"
},
"title": {
"type": "string"
},
"workPhone": {
"type": "string"
}
},
"required": [
"company",
"email",
"firstName",
"lastName",
"nickname",
"prefix",
"sourceId",
"title",
"workPhone"
],
"type": "object"
},
"type": "array"
}
},
"runAfter": {},
"type": "ParseJson"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {}
}

Listing Nested JSON Objects

We have the following JSON structure from an TSheets API which has an actual timesheet 'id' as an object in the hierarchy. This means there's no fixed hierarchy structure and we need to dynamically find a way to loop through each timesheet.
We've stored this data in a variant column, but want to flatten it and have a row per timesheet. Is there a way to list all objects under results.timesheets to retrieve all ids in a single column (i.e. '13510958','13510960') so we can loop through these to obtain the lower level details. Seems like an odd way to construct an API response!
JSON can be found below:
{
"results": {
"timesheets": {
"13510958": {
"id": 13510958,
"user_id": 1360082,
"jobcode_id": 16297998,
"start": "",
"end": "",
"duration": 28800,
"date": "2021-03-29",
"tz": 1,
"tz_str": "Europe/London",
"type": "manual",
"location": "QuickBooks Time web",
"on_the_clock": false,
"locked": 0,
"notes": "",
"customfields": {
"802478": "",
"650642": "",
"650640": "Consulting Services:Services"
},
"last_modified": "2021-04-19T14:34:16+00:00",
"attached_files": [],
"created_by_user_id": 1360067
},
"13510960": {
"id": 13510960,
"user_id": 1360082,
"jobcode_id": 16297998,
"start": "",
"end": "",
"duration": 28800,
"date": "2021-03-30",
"tz": 1,
"tz_str": "Europe/London",
"type": "manual",
"location": "QuickBooks Time web",
"on_the_clock": false,
"locked": 0,
"notes": "",
"customfields": {
"802478": "",
"650642": "",
"650640": "Consulting Services:Services"
},
"last_modified": "2021-04-19T14:34:16+00:00",
"attached_files": [],
"created_by_user_id": 1360067
}}
} }
You can use LATERL FLATTEN, LISTAGG or ARRAY_AGG to get it:
with json_data as ( select parse_json('{
"results": {
"timesheets": {
"13510958": {
"id": 13510958,
"user_id": 1360082,
"jobcode_id": 16297998,
"start": "",
"end": "",
"duration": 28800,
"date": "2021-03-29",
"tz": 1,
"tz_str": "Europe/London",
"type": "manual",
"location": "QuickBooks Time web",
"on_the_clock": false,
"locked": 0,
"notes": "",
"customfields": {
"802478": "",
"650642": "",
"650640": "Consulting Services:Services"
},
"last_modified": "2021-04-19T14:34:16+00:00",
"attached_files": [],
"created_by_user_id": 1360067
},
"13510960": {
"id": 13510960,
"user_id": 1360082,
"jobcode_id": 16297998,
"start": "",
"end": "",
"duration": 28800,
"date": "2021-03-30",
"tz": 1,
"tz_str": "Europe/London",
"type": "manual",
"location": "QuickBooks Time web",
"on_the_clock": false,
"locked": 0,
"notes": "",
"customfields": {
"802478": "",
"650642": "",
"650640": "Consulting Services:Services"
},
"last_modified": "2021-04-19T14:34:16+00:00",
"attached_files": [],
"created_by_user_id": 1360067
}}
}}') raw )
select listagg( v.key , ',' ), array_agg( v.key)
from json_data,
lateral flatten( raw:results.timesheets ) v;
When you want to obtain the lower level details without looping through them, you can also access them directly. For example the timesheet, user_id and duration:
with json_data as (
select parse_json('{
"results": {
"timesheets": {
"13510958": {
"id": 13510958,
"user_id": 1360082,
"jobcode_id": 16297998,
"start": "",
"end": "",
"duration": 28800,
"date": "2021-03-29",
"tz": 1,
"tz_str": "Europe/London",
"type": "manual",
"location": "QuickBooks Time web",
"on_the_clock": false,
"locked": 0,
"notes": "",
"customfields": {
"802478": "",
"650642": "",
"650640": "Consulting Services:Services"
},
"last_modified": "2021-04-19T14:34:16+00:00",
"attached_files": [],
"created_by_user_id": 1360067
},
"13510960": {
"id": 13510960,
"user_id": 1360082,
"jobcode_id": 16297998,
"start": "",
"end": "",
"duration": 28800,
"date": "2021-03-30",
"tz": 1,
"tz_str": "Europe/London",
"type": "manual",
"location": "QuickBooks Time web",
"on_the_clock": false,
"locked": 0,
"notes": "",
"customfields": {
"802478": "",
"650642": "",
"650640": "Consulting Services:Services"
},
"last_modified": "2021-04-19T14:34:16+00:00",
"attached_files": [],
"created_by_user_id": 1360067
}}
}}') raw )
select key, value:user_id, value:duration
from json_data,
lateral flatten(input=>raw:results.timesheets)
I was able to get this to work.
SELECT VALUE AS TIMESHEET_JSON, TIMESHEET_JSON:id AS ID
FROM TABLE(FLATTEN(INPUT=> PARSE_JSON('{Your JSON Here}'):results.timesheets));
You may need to do a little more work to get your JSON into the flatten. A lateral flatten may be useful. This worked once I put your JSON into a one column cte.
SELECT VALUE AS TIMESHEET_JSON, TIMESHEET_JSON:id AS ID
FROM cte
,LATERAL FLATTEN(INPUT=> PARSE_JSON(JSON):results.timesheets);
You can then use typical JSON parsing syntax against the VALUE column for getting at your individual attributes per record.

Join 2 arrays by key and value (AngularJS)

I have 2 objects
{
"_id": "58b7f36b3354c24630f6f3b0",
"name": "refcode",
"caption": "Reference",
"type": "string",
"search": false,
"required": false,
"table": true,
"expansion": true
},
and
{
"_id": "58b7f36b3354c24630f6f3c8",
"vacancyid": "0",
"refcode": "THIS IS MY REF",
"position": "Test",
"jobtype": "Temp",
"department": "Industrial",
"branch": "Office",
"startdate": "02/12/2013",
"contactname": "Person Name",
"contactemail": "person#domain",
"Q_V_TYP": "Daily",
"score": 0
},
Object one defines what a field should be and what it is called
The second object is a job description.
What i need is to match a field to each key (this even sounds confusing i my head, so here is an example)
{
"_id": "58b7f36b3354c24630f6f3c8",
"vacancyid": "0",
"refcode": {
"_id": "58b7f36b3354c24630f6f3b0",
"name": "refcode",
"caption": "Reference",
"type": "string",
"search": false,
"required": false,
"table": true,
"expansion": true,
"value": "THIS IS MY REF"
}
},
"position": "Test",
"jobtype": "Temp",
"department": "Industrial",
"branch": "Office",
"startdate": "02/12/2013",
"contactname": "Person Name",
"contactemail": "person#domain",
"Q_V_TYP": "Daily",
"score": 0
},
Here you go:
var def = {
"_id": "58b7f36b3354c24630f6f3b0",
"name": "refcode",
"caption": "Reference",
"type": "string",
"search": false,
"required": false,
"table": true,
"expansion": true
};
var jobDesc = {
"_id": "58b7f36b3354c24630f6f3c8",
"vacancyid": "0",
"refcode": "THIS IS MY REF",
"position": "Test",
"jobtype": "Temp",
"department": "Industrial",
"branch": "Office",
"startdate": "02/12/2013",
"contactname": "Person Name",
"contactemail": "person#domain",
"Q_V_TYP": "Daily",
"score": 0
};
var jobDescKeysArr = Object.keys(jobDesc);
if (jobDescKeysArr.indexOf(def.name) !== -1) {
// A match.
def.value = jobDesc[def.name];
jobDesc[def.name] = Object.assign({}, def);
console.log(jobDesc)
}

While json_decode i want duplicate key values also in array PHP

I want to have the JSON below as an array with duplicated key values, i.e.:
"2016-09-16":{"available":"1","bind":0,"info":"","notes":"","price":"","promo":"","status":"booked"}
twice. How can I do that?
{
"2016-06-28": {
"available": "1",
"bind": 0,
"info": "",
"notes": "",
"price": "",
"promo": "",
"status": "booked"
},
"2016-06-29": {
"available": "1",
"bind": 0,
"info": "",
"notes": "",
"price": "",
"promo": "",
"status": "booked"
},
"2016-06-30": {
"available": "1",
"bind": 0,
"info": "",
"notes": "",
"price": "",
"promo": "",
"status": "booked"
},
"2016-07-04": {
"available": "1",
"bind": 0,
"info": "",
"notes": "",
"price": "",
"promo": "",
"status": "booked"
},
"2016-07-05": {
"available": "1",
"bind": 0,
"info": "",
"notes": "",
"price": "",
"promo": "",
"status": "booked"
},
"2016-07-06": {
"available": "1",
"bind": 0,
"info": "",
"notes": "",
"price": "",
"promo": "",
"status": "booked"
},
"2016-07-07": {
"available": "1",
"bind": 0,
"info": "",
"notes": "",
"price": "",
"promo": "",
"status": "booked"
},
"2016-09-16": {
"available": "1",
"bind": 0,
"info": "",
"notes": "",
"price": "",
"promo": "",
"status": "booked"
},
"2016-09-15": {
"available": "1",
"bind": 0,
"info": "",
"notes": "",
"price": "",
"promo": "",
"status": "booked"
},
"2016-09-14": {
"available": "1",
"bind": 0,
"info": "",
"notes": "",
"price": "",
"promo": "",
"status": "booked"
},
"2016-09-13": {
"available": "1",
"bind": 0,
"info": "",
"notes": "",
"price": "",
"promo": "",
"status": "booked"
},
"2016-09-16": {
"available": "1",
"bind": 0,
"info": "",
"notes": "",
"price": "",
"promo": "",
"status": "booked"
},
"2016-09-17": {
"available": "1",
"bind": 0,
"info": "",
"notes": "",
"price": "",
"promo": "",
"status": "booked"
}
}
JSON with duplicate keys in the same object is not reliable across JSON parsers (some will choke, some will give you only the value of the last occurrence) and not useful in any case. Use arrays of objects for the values of those date keys, not individual objects:
{
"2016-06-29": [{
"available": "1",
"bind": 0,
"info": "",
"notes": "",
"price": "",
"promo": "",
"status": "booked"
}],
"2016-09-16": [{
"available": "1",
"bind": 0,
"info": "",
"notes": "",
"price": "",
"promo": "",
"status": "booked"
}, {
"available": "1",
"bind": 0,
"info": "",
"notes": "",
"price": "",
"promo": "",
"status": "booked"
}],
"2016-09-15": [{
"available": "1",
"bind": 0,
"info": "",
"notes": "",
"price": "",
"promo": "",
"status": "booked"
}]
}
(Data shortened for clarity.)
In the above, note how 2016-06-29 and 2016-09-15 have arrays with just one entry, but 2016-09-16 has an array with two entries.

Resources