Not able to get parent object's param value
{{#each myObject.details}}
<span class="marginL15 pull-left hidden-xs">
<a href="
/rates
/{{../port_data.name}}
/{{../port_data.name}}
/{{name}}
/{{port_code}}
">
{{name}}
</a>
</span>
{{/each}}
My object is of format
{
"meta_title": "fw",
"port_data": {
"display_name": "Rajkot (INRAJ), Rajkot, India",
"name": "Rajkot",
"port_code": "INRAJ"
},
"details": [
{
"_id": {
"$oid": "58f04ef3c0a35f10b7cc08fa"
},
"display_name": "Sokhna(Al Sokhna) (EGSOK), Suez, Egypt",
"name": "Sokhna(Al Sokhna)",
"port_code": "EGSOK"
},
{
"_id": {
"$oid": "58ff42cfc0a35f493be68031"
},
"display_name": "Rouyn Noranda Airport - CAYUY (YUY), Canada, usa",
"name": "Rouyn Noranda Airport - CAYUY",
"port_code": "YUY"
},
{
"_id": {
"$oid": "58f1c6e9c0a35f2d16dd4f44"
},
"display_name": "Sharjah (AESHJ), Sharjah, United Arab Emirates",
"name": "Sharjah",
"port_code": "AESHJ"
}
]
}
Also tried {{#root.port_data.name}} but to no use.
When passing myObject.details to the {{#each}} helper, you pass only the referenced array stored in the details field of myObject variable - there is no way to look up to something stored in ../, as there's nothing there.
What you could do:
{{#myObject}}
{{#each details}}
<span class="marginL15 pull-left hidden-xs">
<a href="/rates
/{{../port_data.name}}
/{{name}}
/{{port_code}}
">
{{name}}
</a>
</span>
{{/each}}
{{/myObject}}
It gives you an access to the whole myObject variable one scope above the {{#each}} loop.
Related
The following mapping and query DSL dict work OK when the version of ES is 7.10.2, but they never work where the version of ES is 7.16.3:
mappings = \
{
"mappings": {
"properties": {
"esdoc_text": {
"type": "text",
"term_vector": "with_positions_offsets",
"fields": {
"stemmed": {
"type": "text",
"analyzer": "english",
"term_vector": "with_positions_offsets",
}
}
}
}
}
}
search dict:
data = \
{
'query': {
'simple_query_string': {
'query': self.search_string,
'fields': [
self.text_field
]
}
},
'highlight': {
'fields': {
self.text_field: {
'type': 'fvh',
'pre_tags': [
'<span style="background-color: yellow">',
'<span style="background-color: skyblue">',
'<span style="background-color: lightgreen">',
'<span style="background-color: plum">',
'<span style="background-color: lightcoral">',
'<span style="background-color: silver">',
],
'post_tags': [
'</span>', '</span>', '</span>',
'</span>', '</span>', '</span>',
]
}
},
'number_of_fragments': 0
}
}
with version 7.10.2, setting self.text_field to "esdoc_text" (field name) returns highlighted results using a standard analyser, and setting self.text_field to "esdoc_text.stemmed" returns highlighted results using an english analyser.
but with version 7.16.3, with the identical mapping and identical query DSL dict, hits are produced, but they never contain a "highlight" key.
Has anyone got any idea why this might be? Has any modification crept in between 7.10.2 and 7.16.3 which might explain this? Anyone now how to change things?
I want to display data that has been grouped into the EJS?
I have the following data:
"results": {
"Angular CLI": [
{
"category_name": "Angular CLI",
"article_title": "Mengenal Framework Angular CLI"
}
],
"Tips dan Trik": [
{
"category_name": "Tips dan Trik",
"article_title": "Tutorial : Cara Membuat Repositori Github Private"
},
{
"category_name": "Tips dan Trik",
"article_title": "Mengenal Fitur Media Query pada CSS"
}
]
}
Following on the EJS file:
<% results.forEach(function(data) { %>
<div>
<p><%= data %></p>
</div>
<% }); %>
But it does not display data at all.
EDIT :
Dear all, thank you for giving some explanation. So that I can find a solution to this problem.
<% for (let category in results) { %>
<b><%= category %></b>
<% results[category].forEach((data, key) => { %>
<p><%= data.article_title %></p>
<% }) %>
<% } %>
Provided your object is something like this below
var obj = {"results": {
"Angular CLI": [
{
"category_name": "Angular CLI",
"article_title": "Mengenal Framework Angular CLI"
}
],
"Tips dan Trik": [
{
"category_name": "Tips dan Trik",
"article_title": "Tutorial : Cara Membuat Repositori Github Private"
},
{
"category_name": "Tips dan Trik",
"article_title": "Mengenal Fitur Media Query pada CSS"
}
]
}
As your obj.results is object and not array, you could iterate through all properties of obj.results object and display values like this
<% for (var prop in obj.results) { %>
<div>
<p><%= prop%> : <%= results[prop] %></p>
</div>
<% }); %>
Let me know if I misunderstood your issue
I'm testing this markup https://developers.google.com/gmail/markup/reference/invoice on https://script.google.com/, so I discard all the SPF problems.
This is the JS:
function testSchemas() {
var htmlBody = HtmlService.createHtmlOutputFromFile('mail_template').getContent();
MailApp.sendEmail({
to: Session.getActiveUser().getEmail(),
subject: 'Test Email markup - ' + new Date(),
htmlBody: htmlBody,
});
}
And this is the HTML
<html>
<head>
<script type='application/ld+json'>
{
"#context": "http://schema.org",
"#type": "Invoice",
"accountId": "123-456-789",
"minimumPaymentDue": {
"#type": "PriceSpecification",
"price": "$70.00"
},
"paymentDue": "2015-11-22T08:00:00+00:00",
"paymentStatus": "PaymentAutomaticallyApplied",
"provider": {
"#type": "Organization",
"name": "Mountain View Utilities"
},
"totalPaymentDue": {
"#type": "PriceSpecification",
"price": "$70.00"
}
}
</script>
</head>
<body>
<p>
This a test for a Go-To action in Gmail.
</p>
</body>
</html>
As you may see, the code should be fine. Ok, I execute the code and I receive this (please, add "h" at beggining, stackoverflow dont let me add more than 2 links):
https://i.stack.imgur.com/bg8S2.png
https://i.stack.imgur.com/ituM0.png
What I'm doing wrong? one-click actions on http://gmail-actions.appspot.com/ works fine, but I can't get working invoices.
forEach is not a function when I am iterating json file in ejs using nodejs giving some error while iterating.. below is three section what i have done in .ejs file, json and nodeJS
Here is my JSON Data
<pre>
{
"MenuName": "Main Menu Here",
"widget": {
"window": {
"data": "Click Here",
"title": "Sample Konfabulator Widget",
"name": "main_window",
"width": 500,
"height": 500
},
"window": {
"data": "Click Here",
"src": "Images/Sun.png",
"name": "sun1",
"hOffset": 250,
"vOffset": 250,
"alignment": "center"
},
"window": {
"data": "Click Here",
"size": 36,
"style": "bold",
"name": "text1",
"hOffset": 250,
"vOffset": 100,
"alignment": "center",
"onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
}
}
}
</pre>
This is my ejs
<html>
<head>
<title><%= title %></title>
</head>
<body>
<h1> My Name Is <%= title %></h1>
<h1> My Name Is <%= printIt.MenuName %></h1>
<ul>
<% printIt.widget.forEach(function(item){%>
<li><%= item.window.data%></li>
<% }); %>
</ul>
</body>
</html>
</pre>
in NodeJS
<pre>
app.locals.printIt = require("./sample.json");
</pre>
I can able to print
My Name Is <%= title %> and My Name Is <%= printIt.MenuName %>
What i missed here..?
First of all, your JSON data will keep only single record of widget window and which is last one. Because window key will overwrite previous hold value.
Update your script with this one
<ul>
<% for(var item in printIt.widget){%>
<li><%= printIt.widget[item].data%></li>
<% } %>
</ul>
Hope this will help to solve your query !!
I'm new to angularJS. I have a requirement to perform a search on JSON data. Here is an example JSON structure
countries = [
{
"country_name" : "India",
"stations" : [
{
"name": "Dream Factory"
}
]
},
{
"country_name" : "Indonesia",
"stations" : [
{
"name": "Drummer Factory"
},
{
"name": "Beats"
}
]
}
]
Say I type Ind, I need the countries matching the string and return both India and Indonesia
also In other field, typing Factory should retrieve station names which matches the string (here Drummer Factory, Dream Factory).
What is the simple way to achieve this?
Is there any built-in directive which solves this or can I use filters, If yes, please post with example...
You can use the filter named 'filter' (yes it's a little confusing): http://docs.angularjs.org/api/ng.filter:filter
Here's a demo: http://jsfiddle.net/g/pXnRs/4/
HTML:
<div ng-controller="CountryController">
Filter: <input ng-model="nameFilter" />
<ul>
<li ng-repeat="country in countries | filter: nameFilter">
{{country | json}}
</li>
</ul>
</div>
JS:
var app = angular.module('app', []);
app.controller('CountryController', function($scope){
$scope.nameFilter = '';
$scope.countries = [
{
"country_name" : "India",
"stations" : [
{
"name": "Dream Factory"
}
]
},
{
"country_name" : "Indonesia",
"stations" : [
{
"name": "Drummer Factory"
},
{
"name": "Beats"
}
]
}];
});
angular.bootstrap(document, ['app']);
If you need stations only as results, you should first flatten the JSON object hierarchy into a list of stations.