简体   繁体   中英

How do I map a JSON object to form using Dojo Toolkit?

Does Dojo support JSON Object to dijit/form/Form mapping? I'm well aware of this but I couldn't find any detailed example of how to do this.

so if I understand well enough (the question is not really that detailed), you want to use an object and all the properties of that object should map to fields in your form? Well, that's possible using the getValues() and setValues() function.

For example:

var myObject = {
    test1: "test5",
    test2: "test6",
    test3: "test7",
    test4: "test8"
};
registry.byId("form").setValues(myObject);

Retrieving the same kind of object can be done with the appropriate getter, for example:

registry.byId("form").getValues();

I also made an example using JSFiddle .

DOJO plugin is deprecated in struts 2.1.x - http://struts.apache.org/release/2.1.x/docs/ajax-tags.html

Better use annotations for JSON to form binding , check this - How to bind JSON to Java object in Struts2 using struts2-json-plugin

Dojo has an MVC package, used for binding elemnts to JSON values. The dojo/mvc/at does the widget to json binding

http://dojotoolkit.org/reference-guide/1.9/dojox/mvc.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM