Thanks Rasika for the solution. In the client side JS, have the following code :
<script type="text/javascript"> var protocols = *{{{protocols}}}*; $.each(protocols, function(index, value) { $('#queue-subscription-protocols').append($('<option>').text(value).attr('value', index)); }); </script> Have to use 3 curly braces. Regards, Hemika Hemika Kodikara Software Engineer WSO2 Inc. lean . enterprise . middleware http://wso2.com Mobile : +94777688882 On Fri, Jun 10, 2016 at 2:00 PM, Hemika Kodikara <hem...@wso2.com> wrote: > Hi Milinda, > > It is not a string array, its actually java objects that is there. > > Hi Sajith, > > I modified the nashorn script as following : > > var onRequest = function (context) { > var protocols = callOSGiService("org.wso2.andes.kernel.Andes", > "getSupportedProtocols", []); > var protocolStrings = []; > for each (var item in protocols) { > protocolStrings.push(item.toString()); > } > > // var protocolsJson = JSON.stringify(protocolStrings); > return {"protocols" : protocolStrings}; > }; > > I am assigning the "protocols" json value to a javascript variable in the > client-side as following : > > var protocols =* {{protocols}}*; > $.each(protocols, function(index, value) { > > ('#queue-subscription-protocols').append($('<option>').text(value).attr('value', > index)); > }); > > > But I am getting the following errors when rendered the page(client side > js) : > > var protocols = [object Array]; <-- Syntax error > > When I use JSON.stringify in server side js, I get the following output : > > var protocols = > ["AMQP-0-10","MQTT-default","AMQP-0-91","AMQP-8-0","AMQP-0-9"]; > <-- Unexpected token & > > Any Idea ? > > Regards, > Hemika > > > Hemika Kodikara > Software Engineer > WSO2 Inc. > lean . enterprise . middleware > http://wso2.com > > Mobile : +94777688882 > > On Fri, Jun 10, 2016 at 12:51 PM, Milinda Perera <milin...@wso2.com> > wrote: > >> Hi Hemika, >> >> If AMQP-0-10, MQTT-default, AMQP-0-91, AMQP-8-0, AMQP-0-9 are strings, >> following should work >> >> JSON.parse("[\"AMQP-0-10\", \"MQTT-default\", \"AMQP-0-91\", >> \"AMQP-8-0\", \"AMQP-0-9\"]") >> >> Accroding to [1] within array " A *value* can be a *string* in double >> quotes, or a *number*, or true or false or null, or an *object* or an >> *array*. These structures can be nested." >> >> [1] http://www.json.org/ >> >> Thanks, >> Mili >> >> On Fri, Jun 10, 2016 at 12:33 PM, Hemika Kodikara <hem...@wso2.com> >> wrote: >> >>> Hi All, >>> >>> I am invoking the callOSGiService method in nashorn to get a list of >>> protocols thats in andes of MB. >>> >>> I am getting the following output after invoking the callOSGiService : >>> [AMQP-0-10, MQTT-default, AMQP-0-91, AMQP-8-0, AMQP-0-9] >>> >>> But need to convert it into a javascript array(Probably a String array). >>> Need to bind it to a dropdown(select element). >>> >>> I tried JSON.parse, but getting the following errors : >>> >>> jjs> JSON.parse("[AMQP-0-10, MQTT-default, AMQP-0-91, AMQP-8-0, >>> AMQP-0-9]"); >>> <shell>:1 SyntaxError: Invalid JSON: <json>:1:1 Expected json literal >>> but found ident >>> [AMQP-0-10, MQTT-default, AMQP-0-91, AMQP-8-0, AMQP-0-9] >>> ^ >>> >>> jjs> JSON.parse([AMQP-0-10, MQTT-default, AMQP-0-91, AMQP-8-0, >>> AMQP-0-9]); >>> ECMAScript Exception: SyntaxError: <shell>:1:28 Expected an operand but >>> found default >>> JSON.parse([AMQP-0-10, MQTT-default, AMQP-0-91, AMQP-8-0, AMQP-0-9]); >>> ^ >>> >>> My OSGi method returns a Set<ProtocolType>. >>> >>> How can I achieve this ? >>> >>> Regards, >>> Hemika >>> >>> Hemika Kodikara >>> Software Engineer >>> WSO2 Inc. >>> lean . enterprise . middleware >>> http://wso2.com >>> >>> Mobile : +94777688882 >>> >>> _______________________________________________ >>> Dev mailing list >>> Dev@wso2.org >>> http://wso2.org/cgi-bin/mailman/listinfo/dev >>> >>> >> >> >> -- >> Milinda Perera >> Software Engineer; >> WSO2 Inc. http://wso2.com , >> Mobile: (+94) 714 115 032 >> >> >
_______________________________________________ Dev mailing list Dev@wso2.org http://wso2.org/cgi-bin/mailman/listinfo/dev