Using JSON direct in widget

0
I am building a Mendix widget that wraps a jQuery widget that can process JSON formatted data directly. Now I use a mx.processor.get with a callback function that returns a list of mendix objects. I put that objects in a local array and feed it to the jQuery widget. Time and memory consuming. Using JSON could be more effective, but how? Is that done with a mxserver.request? Any sample of how to use it?
asked
1 answers
9

If the jQuery widget has a method setData(data) or displayWidget(data, config, etc) then you could perhaps do:

mx.processor.get({
   xpath : xpath,
   callback : dojo.hitch(this, function(mxObjects) {
     this.jQueryWidget.setData(dojo.map(mxObjects, function(item) {
       return {
         widgetAttr1 : item.getAttribute('someAttr1'),
         widgetAttr2 : item.getAttribute('someAttr2'),
         mxObject : item /* store the mxObject for updates/commits perhaps */}
       };
     });
   })
});

This is perhaps not a big improvement in terms of memory and time consumption, but a mapping of your domain model shouldn't be a time/memory concern (unless your displaying thousands of entity entries).

You should also have a look at the filter property passed to mx.processor.get(). This could reduce the size of the response data (and thus that which is stored in memory) as you can specify which attributes of the given entity you want to receive.

http://apidocs.mendix.com/client/processor.html#get

For more information on the filter property browse the forum, as I've asked a couple of questions on it.

answered