Sunday, 15 February 2015

How to pass a whole dojox.grid.DataGrid store(items json data) to servlet? -


I have a button on the page - when clicked, it sends all the data into the servlet, I can update data. My question is how to pass the whole store as service data, JSN data? Is there an easier way? Thanks

Here are some code that I wrote to store in an object. Then it can be converted to JSON using dojo.toJson (obj); I originally learned about this (give credit where credit is needed). I realize that this code is too big and dirty. When I saw a better way about a year ago, I could not find any one.

  JsonHelper.storeToObject = function (store) {var object = []; Var Index = -1; Store.fetch ({onItem: function (item, request) {object [++ index] = JsonHelper.itemToObject (store, item);}}); Return item; }; JsonHelper.itemToObject = Function (Store, Item) {// store: // Datastore Item came // item: // Item in question var obj = {}; If (item & amp; amp; amp; amp; amp; amp; amp; amp; store; //) property = store.getAttributes; If (attributes & attributes lang> gt;) {var i; For (i = 0; i & lt; attributes.length; i ++) {var value = store.getValues ​​(items, attributes [i]); If (value) {// handle multi-layered and only values ​​(values.length & gt; 1) {var j; Obj [attributes [i]] = []; For (j = 0; j & lt; values.length; j ++) {var value = value [j]; // Check that the value is not another object if it is //, then process it as an item (store.isItem (value)) {obj [attributes [i]]. Push (itemToObject (store, value)); } And {obj [attributes [i]]. Push (value); }}} And {if (store.isItem (value [0]) {obj [attributes [i]] = itemToObject (store, value [0]); } And {obj [attributes [i]] = value [0]; }}}}}} Return obj; };    

No comments:

Post a Comment