Skip to main content

can jmaki controls get data from JSON objects

2 replies [Last post]
thomas_borunda
Offline
Joined: 2007-06-21
Points: 0

If you have javascript file in project with object: var data="[['Item 1','I1'],['Item 2','I2'],['abc','I3']]";

can read it?

- t

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
gmurray71
Offline
Joined: 2003-07-31
Points: 0

Hi T,

You can using what we call a client side value expression.

In your JavaScript that gets called before the widget initializes make sure the variable is assigned. (I put it in the glue.js file which is loaded before widgets).

var data = [
['Item 12','I1'],
['Item 2','I2'],
['Item 3','I3']
];

Next just use the expression @{data} for the value (it needs to be a string)

jMaki will look up the data assigned to data.

You can also used namespaced data and call functions:

In other words if you did :

jmaki.mydata = [
['Item 12','I1'],
['Item 2','I2'],
['Item 3','I3']
];

You can access the data from a widget using:

If you are using something like DWR to get data from Java which uses get / set functions in the stubs you can do the following:

jmaki.getMyData = function() {

return [
['Item 12','I1'],
['Item 2','I2'],
['Item 3','I3']
];
}

And access it using the expression which will be evaluated and assigned to the value of the widget.

I hope you don't mind all the options but I wanted to make sure others could view this as a reference as well.

client side value expressions are evaluated on the client and thus are supported by all server implementations of jMaki (Phobos/PHP/JSP/JSF/Ruby).

thomas_borunda
Offline
Joined: 2007-06-21
Points: 0

Thank you

- t