Iterate through a map that is one level higher in Handlebars - handlebars.js

Let's say I have some JSON like this:
{
'my_items': [{'property': '1'}, {'property': '2'}, {'property': '3'}],
'other_items': [{'other_property': 'a'}, {'other_property': 'b'}, {'other_property': 'c'}]
}
I want to iterate through the my_items first, then in each iteration of my_items, I want to iterate through other_items.
I thought it could be done like this:
{{#my_items}}
<div>{{property}}</div>
{{#../other_items}}
<div>{{other_property}}</div>
{{/../other_items}}
{{/my_items}}
But this doesn't work.

Oops, the variable I was passing to the template didn't have all the data I wanted.

Related

Move an item within a DynamoDB list

I have a list in a DynamoDB table and would like to move items to different positions in the same list, is there a way to do this in a single update?
At the moment, I'm looking at having to read the list, modify it, then write it back again, but would prefer doing it all in a single update, is there a way to do this?
Edit to add example
So here's some noddy data that shows what I'd like to do:
If the data started like this:
Item: { COLUMN: [ "Element_0", "Element_1", "Element_2", "Element_3" ] }
Then I'd give it from and to indices and it would move the element. So for example if I gave it a from index of 0 and to index of 2 the data should end up like this:
Item: { COLUMN: [ "Element_1", "Element_2", "Element_0", "Element_3" ] }
You can do this with an Update Expression, but it's a little tricky, since you don't have the data.
Basically, you have to create a dynamic update statement that sets every value you want to move. Something like this works:
aws dynamodb update-item --table-name test --key '{"pk":{"S":"1"}}' --update-expression "SET #list[1] = #list[2], #list[2] = #list[1]" --region us-west-2 --profile jw-test --expression-attribute-names '{"#list": "list"}'
I created a table with a key of pk, with a value of 1. The list before the update was like this:
[
'one',
'two',
'three',
'four'
]
After the update it looks like this:
[
'one',
'three',
'two',
'four'
]
Default answer if this isn't possible in a single update.
Read out the list, modify it, then write it back. It's not elegant, but it works and isn't that ugly either.
It's not atomic though so any answer that can do it in a single update will get the check mark.

JSONPath to get parameter from an array

I have a response body I believe is an array it looks like this:
{"id":982,"form_stage":"1","customer_hash":"fffae165253f494a95bdb753ca87716c"}
In this case I want to get "customer_hash" and I have tried every combination of $..customer_hash $.customer_hash, etc but none of them work because this doesn't start with "response" or "result" I guess it is an array not an object(?).
Can anyone tell me what would be the JSONPath mapping to get the parameter "customer_hash"?
Try using:
$.customer_hash
Output:
[
"fffae165253f494a95bdb753ca87716c"
]

Loadrunner Parameters in JSON String

I'm trying to use a parameter inside of a JSON string, and would like to use an inner parameter to replace an GUID. I've changed the default parameter start and end characters since curly braces are used in JSON.
I've tried to do something like this, where the json param contains my json which is similar to this below.
{"DashboardGUID":"<Dash_GUID>"}
request_json = lr_eval_string("<json>");
lr_save_string(request_json, "request_json_param");
I'm expecting the lr_eval_string to replace the with the GUID that's in this parameter, what's the best why of replacing this ID in my JSON String?
Not sure what you are asking but I will put this here in case someone comes here in the future:
main.c
Action()
{
lr_eval_json("Buffer/File=my_json.json", "JsonObject=MJO",LAST);
lr_json_stringify("JsonObject=MJO","Format=compact", "OutputParam=newJsonBody",LAST);
lr_save_string(lr_eval_string(lr_eval_string("{newJsonBody}")),"tmp");
web_reg_find("Text={mydate}",LAST);
web_rest("POST",
"URL=http://myServer.microfocus.com/url",
"Method=POST",
"EncType=raw",
"Body={tmp}",
HEADERS,
"Name=Content-Type", "Value=application/json", ENDHEADER,
LAST);
return 0;
}
my_json.json
{
"LastActionId": 0,
"Updated": "{mydate}"
}
Okay so instead of doing what I'm thinking above I ended up creating an array of char's with this {"DashboardGUID":"<Dash_GUID>", someotherdata:"123"} in 10 different positions within the array. I then randomly selected an element from this array and when doing the lr_eval_string the parameter was replaced.
Hopefully this makes sense those looking to do something similar.

Using ProjectionExpression on List that contain maps

Say that this is the table struct:
[{ name:"test", age:99,
Info: [
{ location:"A", num:11 },
{ location:"B", num:99 }
]
}]
What i want to get is something like this:
{ name: "test",
Info:[
{location:"A"},
{location:"B"}
]}
would that be possible? I can't seem to make it work unless I specify the index.
ProjectionExpression="name, #mp[0].location",
Select='SPECIFIC_ATTRIBUTES',
ExpressionAttributeNames={"#mp": "Info"}
How do I do this?
Based on the documentation you can either specify the whole object or with index.
http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.Attributes.html#Expressions.Attributes.NestedAttributes
Working as documented.
Hope it helps.
It's a little tricky if you do not know the length of list. You could try using a max length for the list and use something like (assuming 3 is the max length)
ProjectionExpression="#mp[0].location,#mp[1].location,#mp[2].location"

Iterating over an Array in Meteor

I have the following Test collection where each document looks like:
firstName: "Jeff",
lastname: "Harper",
scores:[ {'period':'week one', 'score':90},
{'period':'week two', 'score':85},
{'period':'week three','score':92},
{'period':'week four', 'score':87}
I would like to iterate through the scores array and console.log the score. As a trial, I have tried:
Test.find()forEach(function(doc){ console.log( doc.firstName ) } );
This works fine to print out the first name. If I would want to print the first score in the array object, i.e., I try the statement:
Test.find()forEach(function(doc){ console.log( doc.scores[0].score ) } );
which doesn't work. How do I gain access to the elements in the array of objects?
Thanks everyone for your input. Christian Fritz identified my problem. Now, I limit my search to only documents that have the object array. Both the forEach method and the fetch() method work now. However, Ethaan, I had to include an inner for-loop inside the primary for-loop to gain access to each internal score. Thanks for your help and your editing and the picture of the beautiful asian princess.

Resources