Iterating over a nested array in api - ReactJS - arrays

I am pulling API data as content for my ReactJS app i'm creating and i'd like to know the best method to iterate over a nested array within an array. Here's the JSON in question:
{
"code": 200,
"status": "Ok",
"copyright": "© 2015 MARVEL",
"attributionText": "Data provided by Marvel. © 2015 MARVEL",
"attributionHTML": "Data provided by Marvel. © 2015 MARVEL",
"etag": "5341faac8eb2f18f592309355057b1c40375545c",
"data": {
"offset": 0,
"limit": 20,
"total": 1,
"count": 1,
"results": [
{
"id": 1011179,
"name": "Pixie",
"description": "",
"modified": "2011-10-19T10:48:27-0400",
"thumbnail": {
"path": "http://i.annihil.us/u/prod/marvel/i/mg/8/e0/4c002f2d626ee",
"extension": "jpg"
},
"resourceURI": "http://gateway.marvel.com/v1/public/characters/1011179",
"comics": {
"available": 6,
"collectionURI": "http://gateway.marvel.com/v1/public/characters/1011179/comics",
"items": [
{
"resourceURI": "http://gateway.marvel.com/v1/public/comics/39737",
"name": "Magneto: Not a Hero (2011) #1"
},
{
"resourceURI": "http://gateway.marvel.com/v1/public/comics/24173",
"name": "Runaways (2008) #10"
},
{
"resourceURI": "http://gateway.marvel.com/v1/public/comics/36943",
"name": "Steve Rogers: Super Soldier Annual (2010) #1"
},
{
"resourceURI": "http://gateway.marvel.com/v1/public/comics/38083",
"name": "X-Men (2010) #19"
},
{
"resourceURI": "http://gateway.marvel.com/v1/public/comics/41118",
"name": "X-Men (2010) #19 (Mc 50th Anniversary Variant)"
},
{
"resourceURI": "http://gateway.marvel.com/v1/public/comics/38404",
"name": "X-Men: Second Coming Revelations (Trade Paperback)"
}
],
"returned": 6
},
"series": {
"available": 5,
"collectionURI": "http://gateway.marvel.com/v1/public/characters/1011179/series",
"items": [
{
"resourceURI": "http://gateway.marvel.com/v1/public/series/14683",
"name": "Magneto: Not a Hero (2011 - 2012)"
},
{
"resourceURI": "http://gateway.marvel.com/v1/public/series/5338",
"name": "Runaways (2008 - 2009)"
},
{
"resourceURI": "http://gateway.marvel.com/v1/public/series/13192",
"name": "Steve Rogers: Super Soldier Annual (2010 - Present)"
},
{
"resourceURI": "http://gateway.marvel.com/v1/public/series/9906",
"name": "X-Men (2010 - 2013)"
},
{
"resourceURI": "http://gateway.marvel.com/v1/public/series/13832",
"name": "X-Men: Second Coming Revelations (2011 - Present)"
}
],
"returned": 5
},
"stories": {
"available": 6,
"collectionURI": "http://gateway.marvel.com/v1/public/characters/1011179/stories",
"items": [
{
"resourceURI": "http://gateway.marvel.com/v1/public/stories/53571",
"name": "Interior #53571",
"type": "interiorStory"
},
{
"resourceURI": "http://gateway.marvel.com/v1/public/stories/81928",
"name": "Steve Rogers: Super Soldier Annual (2010) #1",
"type": "interiorStory"
},
{
"resourceURI": "http://gateway.marvel.com/v1/public/stories/90198",
"name": "Magneto: Not a Hero (2011) #1 - Int",
"type": "interiorStory"
},
{
"resourceURI": "http://gateway.marvel.com/v1/public/stories/90479",
"name": "X-MEN: SECOND COMING REVELATIONS TPB",
"type": "cover"
},
{
"resourceURI": "http://gateway.marvel.com/v1/public/stories/93085",
"name": "X-Men (2010) #19, Mc 50th Anniversary Variant",
"type": "cover"
},
{
"resourceURI": "http://gateway.marvel.com/v1/public/stories/94024",
"name": "X-Men #19 Interior",
"type": "interiorStory"
}
],
"returned": 6
},
"events": {
"available": 0,
"collectionURI": "http://gateway.marvel.com/v1/public/characters/1011179/events",
"items": [],
"returned": 0
},
"urls": [
{
"type": "detail",
"url": "http://marvel.com/characters/1758/pixie?utm_campaign=apiRef&utm_source=86e8919c441293aef435c128e5b5c53a"
},
{
"type": "wiki",
"url": "http://marvel.com/universe/Pixie_%28Eternal%29?utm_campaign=apiRef&utm_source=86e8919c441293aef435c128e5b5c53a"
},
{
"type": "comiclink",
"url": "http://marvel.com/comics/characters/1011179/pixie?utm_campaign=apiRef&utm_source=86e8919c441293aef435c128e5b5c53a"
}
]
}
]
}
and here's my MarvelBios.jsx file that contains the render of the data:
var React = require('react');
module.exports = React.createClass({
propTypes: {
username: React.PropTypes.string.isRequired,
bios: React.PropTypes.object.isRequired
// bios is the entireity of data from the JSON pulled in by Axios for the user inputted character name ("username")
},
render: function() {
var results = this.props.bios.data.results.map(function(result, index) {
return (
<div className="bios" key={index}>
<img src={result.thumbnail.path + "/landscape_xlarge." + result.thumbnail.extension} />
{result.name && <p>{result.name}</p>}
{result.description && <small> {result.description}</small>}
<p></p>
</div>
);
});
return (
<div>
{results}
</div>
)
}
});
I am able to successfully pull in the my first array of data from the JSON, which is results (contains character name, description and thumbnail image).
What i'd like to do is then reference the sub-array called items under that main results array, but i'm having difficulty constructing the proper code. For example I tried creating a var items = result.series.items.map(function(item, i) nested under the existing var results but that returned an undefined.
Thanks for any help.

Something like this perhaps.
module.exports = React.createClass({
propTypes: {
username: React.PropTypes.string.isRequired,
bios: React.PropTypes.object.isRequired
// bios is the entireity of data from the JSON pulled in by Axios for the user inputted character name ("username")
},
render: function() {
var results = this.props.bios.data.results.map(function(result, index) {
var items = results.comics.items.map(function(item) {
return <div>{item}</div>;
});
return (
<div className="bios" key={index}>
<img src={result.thumbnail.path + "/landscape_xlarge." + result.thumbnail.extension} />
{result.name && <p>{result.name}</p>}
{result.description && <small> {result.description}</small>}
<p>{items}</p>
</div>
);
});
return (
<div>
{results}
</div>
)
}
});

Related

How to prevent fields in react-json-schema-form from appearing row by row

I am creating forms using React-json-schema-form. I don't understand how am I suppose to change the layout of the forms I create. They appear in rows by default and adding classes to each field in the uiSchema does not reflect the desired change. I tried adding col-3 etc and they neither change size nor stop appearing in rows.
Its so complex to figure out. My understand would be to change the default behaviour of the fields. But, I'm sure it should be able to be designed out of the box right?
This is what I want to do but its outdated and I still don't know how to use it. https://github.com/audibene-labs/react-jsonschema-form-layout.
How do I change the layout?
import React, { Component, Fragment } from "react";
import axios, { existing_api, new_api, public_path } from "../../../Api/api";
import 'bootstrap/dist/css/bootstrap.css';
//import Form from "#rjsf/core";
import Form from "#rjsf/bootstrap-4";
class POSView extends Component {
constructor(props) {
super(props);
this.state = {
hotelId: 1,
isActive: 1,
formData: { 'recordIn': 10096 },
schema: props.schema || {
"title": "POS",
"description": "Add POS Invoice - Rooms",
"type": "object",
"properties": {
"customer": { "title": "Customer", "type": 'string', "default": '' },
"room": { "title": "Room", "type": 'integer', "default": '' },
"address": { "title": "Address", "type": 'string' },
"company": { "title": "Company", "type": 'string' },
"dueAmount": { "title": "Due Amount", "type": 'string' },
"roomRate": { "title": "Room Rate", "type": 'string' },
"recordIn": { "title": "Record In", "type": 'number', enum: [10096, 10097], enumNames: ["Guest Ledger Control A/c", "Accounts Receivable"] },
"department": { "title": "Department", "type": 'number', enum: [1, 2], enumNames: ["Head Office", "Accounts"] },
"id": { "title": "ID", "type": 'string' },
"invoiceNumber": { "title": "Invoice Number", "type": 'string' },
"invoiceDate": { "title": "Invoice Date", "type": 'string', "format": "date-time" },
"btcCompany": { "title": "BTC Company", "type": 'number', enum: [1, 2], enumNames: ["Limited Standard", "Standard Limited"] },
"itemsAndServices":
{
"title": "Item And Service",
"description": "Add items and Services",
"type": "array",
"items": {
"type": "object",
//"required": [''],
"properties":
{
"Number": { "type": "number" },
"Item Name": {
"title": "Item Name",
"type": "string"
},
"Item Notes": {
"title": "Item Notes",
"type": "string"
},
"Qty": {
"title": "Qty",
"type": "number"
},
"Unit": {
"title": "Unit",
"type": "string"
},
"Price": {
"title": "Price",
"type": "number"
},
"%": {
"title": "%",
"type": "number"
},
"Extended": {
"title": "Extended",
"type": "number"
}
}
}
},
"payment":
{
"title": "Payment",
"description": "",
"type": "array",
"items": {
"type": "object",
//"required": [''],
"properties":
{
"date": { "title": "Date", "type": "string", format: "date-time" },
"amount": { "title": "Amount", "type": "number" },
"cheque": { "title": "Cheque #", "type": "integer" },
"memo": { "title": "Memo", "type": "string" },
"recordIn": { "title": "Record In", "type": 'number', enum: [10096, 10097], enumNames: ["Guest Ledger Control A/c", "Accounts Receivable"] },
// dynamically populate
}
}
}
}
},
uiSchema: props.uiSchema || {
// customer:{'className':""},
// room:{'className':"", },
// address: {'className':"", "ui:disabled": true, },
// company: {'className':"", "ui:disabled": true, },
// dueAmount: {'className':"", "ui:disabled": true, },
// roomRate: {'className':"", "ui:disabled": true, },
// recordIn:{'className':"", },
// department:{'className':"", },
// id:{'className':"", },
// invoiceNumber: {'className':"", "ui:disabled": true, },
// invoiceDate:{'className':"", },
// btcCompany:{'className':"", },
// itemsAndServices:{'className':""},
//items: { className: "container col-offset-6 col-md-3" }
// 'ui:field': 'layout', HOW I expected the default library to work
// 'ui:layout': [
// {
// customer: { md: 6 },
// room: { md: 6 }
// }, {
// address: { md: 12 }
// }, {
// company: { md: 6 },
// dueAmount: { md: 6 }
// }
// ]
// },
// fields:
// {
// layout: LayoutField
}
};
this.onChange = this.onChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
};
onChange({ formData }) {
formData.address = "";
console.log(formData);
this.state.schema.description = "this is beta plus plus";
this.setState({
formData: formData,
});
}
handleSubmit({ formData }) {
// Submit to an api
console.log(formData);
}
render() {
return (
<div className="container">
<div className="col-4">
{/* <div class="row">
<h1 class="col">First Form</h1>
</div><br /> */}
<div>
<Form
schema={this.state.schema}
formData={this.state.formData}
uiSchema={this.state.uiSchema}
//fields={this.state.fields}
onChange={this.onChange}
onSubmit={this.handleSubmit} />
</div>
</div>
</div>
);
}
}
export default POSView;

Using React to create Maps with AmMaps

I am using ReactJs to create USA Map with AmCharts library. What I want exactly is this: https://www.amcharts.com/demos/us-heat-map/. When you check it's code on fiddle, you will note they have used a separate library for the US map in the script tag.
I checked the amcharts documentation with react here https://github.com/amcharts/amcharts3-react but couldn't find it much helpful. How can I implement this Map or any other county map using React? Am I supposed to include the library of the USA in my index.html file? I tried this approach, but I see an empty screen without any errors. Check my code below:
import React, {Component} from 'react';
import AmCharts from "#amcharts/amcharts3-react";
export default class Map extends Component {
render(){
return(
<div>
<AmCharts.React style={{width: "100%",height: "500px"}}
options={{
"type": "serial",
"theme": "light",
"dataProvider": {
"map": "usaLow",
"areas": [ {
"id": "US-AL",
"value": 4447100
}, {
"id": "US-AK",
"value": 626932
}, {
"id": "US-AZ",
"value": 5130632
}, {
"id": "US-AR",
"value": 2673400
}, {
"id": "US-CA",
"value": 33871648
}, {
"id": "US-CO",
"value": 4301261
}, {
"id": "US-CT",
"value": 3405565
}, {
"id": "US-DE",
"value": 783600
}, {
"id": "US-FL",
"value": 15982378
}, {
"id": "US-GA",
"value": 8186453
}, {
"id": "US-HI",
"value": 1211537
}, {
"id": "US-ID",
"value": 1293953
}, {
"id": "US-IL",
"value": 12419293
}, {
"id": "US-IN",
"value": 6080485
}, {
"id": "US-IA",
"value": 2926324
}, {
"id": "US-KS",
"value": 2688418
}, {
"id": "US-KY",
"value": 4041769
}, {
"id": "US-LA",
"value": 4468976
}, {
"id": "US-ME",
"value": 1274923
}, {
"id": "US-MD",
"value": 5296486
}, {
"id": "US-MA",
"value": 6349097
}, {
"id": "US-MI",
"value": 9938444
}, {
"id": "US-MN",
"value": 4919479
}, {
"id": "US-MS",
"value": 2844658
}, {
"id": "US-MO",
"value": 5595211
}, {
"id": "US-MT",
"value": 902195
}, {
"id": "US-NE",
"value": 1711263
}, {
"id": "US-NV",
"value": 1998257
}, {
"id": "US-NH",
"value": 1235786
}, {
"id": "US-NJ",
"value": 8414350
}, {
"id": "US-NM",
"value": 1819046
}, {
"id": "US-NY",
"value": 18976457
}, {
"id": "US-NC",
"value": 8049313
}, {
"id": "US-ND",
"value": 642200
}, {
"id": "US-OH",
"value": 11353140
}, {
"id": "US-OK",
"value": 3450654
}, {
"id": "US-OR",
"value": 3421399
}, {
"id": "US-PA",
"value": 12281054
}, {
"id": "US-RI",
"value": 1048319
}, {
"id": "US-SC",
"value": 4012012
}, {
"id": "US-SD",
"value": 754844
}, {
"id": "US-TN",
"value": 5689283
}, {
"id": "US-TX",
"value": 20851820
}, {
"id": "US-UT",
"value": 2233169
}, {
"id": "US-VT",
"value": 608827
}, {
"id": "US-VA",
"value": 7078515
}, {
"id": "US-WA",
"value": 5894121
}, {
"id": "US-WV",
"value": 1808344
}, {
"id": "US-WI",
"value": 5363675
}, {
"id": "US-WY",
"value": 493782
} ]
}
}} />
</div>
);
}
}
I added following libraries from http://jsfiddle.net/api/post/library/pure/ to my index.html file
<script src="https://www.amcharts.com/lib/3/amcharts.js"></script>
<script src="https://www.amcharts.com/lib/3/serial.js"></script>
<script src="https://www.amcharts.com/lib/3/themes/light.js"></script>
<script src="https://www.amcharts.com/lib/3/ammap.js"></script>
<script src="https://www.amcharts.com/lib/3/maps/js/usaLow.js"></script>
<script src="https://www.amcharts.com/lib/3/plugins/export/export.min.js">
</script>
If this is not the right way, please let me know the correct approach.
In a plain create-react-app just place this code in your App.js
import React, { Component } from 'react';
import AmCharts from "#amcharts/amcharts3-react";
class App extends Component {
render(){
//config as same as yours but inside const
const config = {
"type": "map",
"theme": "light",
"colorSteps": 10,
"dataProvider": {
"map": "usaLow",
"areas": [{
"id": "US-AL",
"value": 4447100
},{//..all areas mentioned in question}]
},
"areasSettings": {
"autoZoom": true
},
"valueLegend": {
"right": 10,
"minValue": "little",
"maxValue": "a lot!"
},
"listeners": [{
"event": "descriptionClosed",
"method": function(ev) {
ev.chart.selectObject();
}
}]
};
return (
<div className="App">
<AmCharts.React style={{ width: "100%", height: "500px" }} options={config} />
</div>);
}
}
its enough to include these into index.html
<link href="https://www.amcharts.com/lib/3/ammap.css" rel="stylesheet">
<script src="https://www.amcharts.com/lib/3/ammap.js"></script>
<script src="https://www.amcharts.com/lib/3/maps/js/usaLow.js"></script>
<script src="https://www.amcharts.com/lib/3/themes/light.js"></script>

How to query critical JSON into ionic

I received the JSON response from the server mentioned below.
{
"employeeId": null,
"id": "DB06442E-2993-4FE8-B496-5A0CF61C8342",
"message": null,
"objects": [
{
"Children": [],
"Fields": [
{
"Key": "CallID",
"Value": 1000
},
{
"Key": "CallDate",
"Value": "Sep 9 2016 10:14AM"
},
{
"Key": "ClientName",
"Value": ""
},
{
"Key": "AssetName",
"Value": "Automatic Cold Cranking Simulator"
},
{
"Key": "CallCategory",
"Value": "Corrective Maintenance"
}
],
"Type": 8
},
{
"Children": [],
"Fields": [
{
"Key": "CallID",
"Value": 1000
},
{
"Key": "CallDate",
"Value": "Sep 9 2016 10:20AM"
},
{
"Key": "ClientName",
"Value": ""
},
{
"Key": "AssetName",
"Value": "Auto Mini Pour Point Tester "
},
{
"Key": "CallCategory",
"Value": "Preventive Maintenance"
}
],
"Type": 8
},
{
"Children": [],
"Fields": [
{
"Key": "CallID",
"Value": 1000
},
{
"Key": "CallDate",
"Value": "Sep 9 2016 10:23AM"
},
{
"Key": "ClientName",
"Value": ""
},
{
"Key": "AssetName",
"Value": "Balance - Citizon CX 220"
},
{
"Key": "CallCategory",
"Value": "Calibration"
}
],
"Type": 8
},
{
"Children": [],
"Fields": [
{
"Key": "CallID",
"Value": 1001
},
{
"Key": "CallDate",
"Value": "Sep 9 2016 10:26AM"
},
{
"Key": "ClientName",
"Value": ""
},
{
"Key": "AssetName",
"Value": "Others"
},
{
"Key": "CallCategory",
"Value": "Installation"
}
],
"Type": 8
}
],
"success": true
}
Can you please explain me bit more as per my json structure.
myhtml.html
<ion-item class="item-remove-animate item-avatar item-icon-right" ng-repeat="item in callItems" type="item-text-wrap" ng-click="doTask()">
<h3 style="color:black;">{{item.CallID}}</h3>
<h3 style="color:black;">{{item.CallDate}}</h3>
<p style="color:black;">{{item.ClientName}}</p>
<p style="color:black;">{{item.AssetName}}</p>
<p style="color:black;">{{item.CallCategory}}</p>
</ion-item>
myjs.js
$http.post("http://testCrm.com/GetAllObjects",
{"objectId":null,"objects":null,"searchParams":null,"sessionId":"DB06442E-2993-4FE8-B496-5A0CF61C8342","type":8})
.success(function(data) {
alert("SUCCESS!");
$rootScope.callItems = data;
console.log($rootScope.callItems);
})
.error(function(data) {
alert("ERROR");
alert(data);
});
As per my code I can able to get the response But How can i parse the value in View ?
you can follow this also
<div ng-repeat="(key, value) in item.Fields">
<h3 style="color:black;"> {{value.Value}}</h3>
</div>
<button ng-click=something($index,item.Fields[0].Value)>check it</button>
</div>
js
add the below function and see u will get a alert with index
$scope.something=function(a,b){
alert(a);//alerts index
alert(b);//alerts CaalID of that index
}
working codepen
new requirments
this might not be the best solution but it's a working demo. i think you need to change the json object structure again and re create it according to your requirement.
<div ng-repeat="item in callItems.objects">
<div ng-repeat="fi in item" >
<div ng-repeat="kk in fi">
<h3 style="color:black;" ng-if="kk.Key == 'CallID'">{{kk.Value}}</h3>
<h3 style="color:black;" ng-if="kk.Key == 'CallDate'">{{kk.Value}}</h3>
<h3 style="color:black;" ng-if="kk.Key == 'ClientName'">{{kk.Value}}</h3>
<h3 style="color:black;" ng-if="kk.Key == 'AssetName'">{{kk.Value}}</h3>
<h3 style="color:black;" ng-if="kk.Key == 'CallCategory'">{{kk.Value}}</h3>
</div>
</div>

Underscore js to retrieve data from array

I'm assigned a task to get data using underscore js.
This is my JSON :
$scope.myData= {
"buslist":
{
"code":"1",
"message":"Success",
"fromStationCode":"71",
"searchResult": [
{
"arrivalTime": "17:00:00",
"availableSeats": "42",
"boardingPointDetails": [
{
"code": "1631",
"name": "Koyambedu",
"time": "09:30:00"
},
{
"code": "961296",
"name": "Nerkundram",
"time": "09:45:00"
}
]
},
{
"arrivalTime": "18:00:00",
"availableSeats": "32",
"boardingPointDetails": [
{
"code": "2084",
"name": "Adyar",
"time": "09:30:00"
},
{
"code": "961296",
"name": "Madurai",
"time": "09:45:00"
}
]
}
]
}
}
From this I want only "name" field. By doing this :
$scope.bdata = _.pluck($scope.myTest.buslist.searchResult, 'boardingPointDetails');
I got all "boardingPointDetails". The result looks like:
[ [
{
"code": "2084",
"name": "Adyar",
"time": "09:30:00"
},
{
"code": "961296",
"name": "Madurai",
"time": "09:45:00"
}
],[
{
"code": "1631",
"name": "Koyambedu",
"time": "09:30:00"
},
{
"code": "961296",
"name": "Nerkundram",
"time": "09:45:00"
}
],[
{
...
}
]
...
]
Help me to retrieve only "name" from this.
If you just want array of names like ['Koyambedu', 'Madurai'] then below code would work.
$scope.bdata = _.pluck($scope.myTest.buslist.searchResult, 'boardingPointDetails');
// Flatten the data.
$scope.flatbdata = _.flatten($scope.bdata, true);
$scope.flatbdata = $scope.flatbdata.filter(function(d){
return d != undefined && d.hasOwnProperty('name')
})
// map calls a provided callback function once for each element in an array, in order, and constructs a new array from the results
$scope.names = $scope.flatbdata.map(function(d){
return d.name;
});
Refer below links :
http://underscorejs.org/#flatten
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map
If you just want the array of names, here it is:
$scope.bdata = _.pluck($scope.myTest.buslist.searchResult, 'boardingPointDetails');
var res= _.flatten($scope.bdata);
res=_.pluck(res,'name');
console.log(res);
var temp = _.pluck(_.flatten($scope.bdata),'name')
temp will have ["Koyambedu", "Nerkundram", "Adyar", "Madurai"]
Try this.
$scope = {}; // in real project you don't need this. it's just for snippet.
$scope.myData = {
"buslist": {
"code": "1",
"message": "Success",
"fromStationCode": "71",
"searchResult": [{
"arrivalTime": "17:00:00",
"availableSeats": "42",
"boardingPointDetails": [{
"code": "1631",
"name": "Koyambedu",
"time": "09:30:00"
}, {
"code": "961296",
"name": "Nerkundram",
"time": "09:45:00"
}]
}, {
"arrivalTime": "18:00:00",
"availableSeats": "32",
"boardingPointDetails": [{
"code": "2084",
"name": "Adyar",
"time": "09:30:00"
}, {
"code": "961296",
"name": "Madurai",
"time": "09:45:00"
}]
}]
}
};
$scope.names = _.chain($scope.myData.buslist.searchResult).pluck("boardingPointDetails").flatten(true).map(function(item) {
return item.name;
}).value();
console.log($scope.names);
<script src="http://underscorejs.ru/underscore-min.js"></script>

Multi-dimensional arrays in Mandrill with handlebars

I'm trying to loop through a multi-dimensional array to get properties of products that are part of line items. They look basically like this: (I did a json_encode so it would be easier to read)
[{
"rcpt": "email#email.com",
"vars": [{
"name": "SYSTEM",
"content": "Bikes"
}, {
"name": "CUSTOMERSERVICE",
"content": "(855-553-4889)"
}, {
"name": "IMAGE",
"content": "http:\/\/www.url.com\/assets\/images\/chicago\/email\/dear_member.jpg"
}, {
"name": "LINKCOLOR",
"content": "#3db7e4"
}, {
"name": "FACEBOOK",
"content": "Bikes"
}, {
"name": "TWITTER",
"content": "Bikes"
}, {
"name": "INSTAGRAM",
"content": "Bikes"
}, {
"name": "CLOSING",
"content": "Greetings"
}, {
"name": "item",
"content": [{
"lineItem": 1,
"id": "3",
"name": "24-Hour Pass Gift Certificate",
"quantity": 2,
"nameShort": "24-Hour",
"type": "Gift Certificate",
"image": "24hour_blank.jpg",
"price": "9.95",
"total": "19.90",
"taxable": false,
"giftCertificates": {
"3204": {
"id": "3204",
"redemptionNumber": "xxxxx",
"type": "24-Hour"
},
"3205": {
"id": "3205",
"redemptionNumber": "xxxxx",
"type": "24-Hour"
}
}
}, {
"lineItem": 2,
"id": "1",
"name": "Annual Membership Gift Certificate",
"quantity": 2,
"nameShort": "Annual",
"type": "Gift Certificate",
"image": "annual_blank.jpg",
"price": "75.00",
"total": "150.00",
"taxable": false,
"giftCertificates": {
"892": {
"id": "892",
"redemptionNumber": "xxxxxx",
"type": "Annual"
},
"893": {
"id": "893",
"redemptionNumber": "xxxxx",
"type": "Annual"
}
}
}]
}, {
"name": "orderID",
"content": 1220
}, {
"name": "giftMessage",
"content": false
}, {
"name": "email",
"content": "email#email.com"
}, {
"name": "transactionDate",
"content": "12\/23\/2015"
}, {
"name": "transactionTime",
"content": "12:21 pm"
}, {
"name": "salesTaxTotal",
"content": 0
}, {
"name": "salesTaxRatePercent",
"content": "6.250"
}, {
"name": "TransactionAmount",
"content": "169.90"
}, {
"name": "account_number",
"content": "XXXX1111"
}, {
"name": "card_type",
"content": "Visa"
}, {
"name": "firstName",
"content": "tetete"
}, {
"name": "lastName",
"content": "tethuhhu"
}, {
"name": "address",
"content": "295 Place St"
}, {
"name": "city",
"content": "Brooklyn"
}, {
"name": "state",
"content": "NY"
}, {
"name": "zip",
"content": "11238"
}, {
"name": "country",
"content": "US"
}, {
"name": "phone",
"content": "8888888888"
}, {
"name": "transactionId",
"content": "xxxxxx"
}, {
"name": "shipToFirstName",
"content": "tetete"
}, {
"name": "shipToLastName",
"content": "tethuhhu"
}, {
"name": "shipToAaddress",
"content": "295 Place St"
}, {
"name": "shipToCity",
"content": "Brooklyn"
}, {
"name": "shipToState",
"content": "NY"
}, {
"name": "shipToZipCode",
"content": "11238"
}, {
"name": "ShipToCountry",
"content": "US"
}, {
"name": "ShipToCountry",
"content": "US"
}]
}]
So I am trying to get a print out of each gift certificate's type and redemption number. When I iterate through {{ giftCertificates }} like this:
{{#each giftCertificates}}
{{type}} {{redemptionNumber}}
{{/each}}
I get one of the line items but not the other. I'm guessing maybe it is being overwritten when it loops through again? But I have also tried to loop through {{ item }} and grab {{ giftCertificates.type }} and {{ giftCertificates.redemptionNumber }} and that does not work either. What is the correct way to get all of these from each line item?
Thanks for your help.
I know this is a very old question, but:
you can use {{this.proprietyName}} to get the type and number:
{{#each giftCertificates}}
{{this.892.type}}
{{/each}}
do not forget to add this to the mandrill message o
"merge": true,
"merge_language": "handlebars",
Also, the data structure is not ideal:
giftCertificates[
{
"id": "892",
"redemptionNumber": "xxxxxx",
"type": "Annual"
},
{
"id": "893",
"redemptionNumber": "xxxxxx",
"type": "Annual"
}
]
would be easier to handle.

Resources