Questions about Braces Syntax Usage in Mustache Template

Hi all,

I returned three messages in an array from a function. All three messages are returned in JSON format.

The following is the result that I can see in debug:

How to pass these three messages in mustache template (payload[0], payload[1] and payload[2] separately)?

I aware that payload[0], payload[1] and payload[2] are the values, but I don't think payload[0] syntax will work in mustache template.

I also have another question. For example, I have the following function:

msg.topic="SELECT * FROM location";

var msg1={};
msg1.topic="SELECT * FROM type";

return [msg,msg1];

If I'm passing msg value to mustache template, {{{payload}}} is the syntax.

If I'm passing msg1 value to the mustache template, how is the syntax going to be?

Thanks for helping.

Hi,

to access array properties in mustache syntax, you have to use the dot-syntax: payload.0

When you return two messages from a Function with [msg , msg1], then msg will be sent out of the first Function node output and msg1 will be sent out of the second output.

If you return [ [msg, msg1] ] then they will be both sent from the first output, one after the other. That is an important thing to understand - they are sent one after the other. The Template node does not receive both messages at the same time - they arrive as individual messages.

It does not matter what you called the local variable in the Function node, when a message arrives at a Template node its the message. So {{{payload}}} will always refer to the payload property of the message the Template node is currently handling.

Hi Nick,

Thanks for the explanation.

I'm using JSGrid to display data and perform CRUD operation. The fields with type "select" (dropdown) are not displaying data. Once I click to add and edit data, I'm unable to make the fields to appear as dropdown with options from the database (e.g. Location_Name from location table). I just would like to make this work.

Here's the link of the topic for more information: Gridview with CRUD Options (MySQL)

I tried the following syntax to access array properties in mustache template, but I'm unable to display the data. Maybe the syntax is incorrect.

var db = {{{payload.0}}}; //payload[0] (Data for main)
var loc = {{{payload.1}}}; //payload[1] (Data for dropdown 1)
var mac = {{{payload.2}}} //payload[2] (Data for dropdown 2)

{
	title: "Location",
	name: "location",
	type: "select",
	items: loc,
	width: 100
}

{
	title: "Type",
	name: "type",
	type: "select",
	items: mac,
	width: 100
}

Hope to hear from you soon. Thanks for helping.