简体   繁体   English

如何使用Dojo Toolkit将JSON对象映射到表单?

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

Does Dojo support JSON Object to dijit/form/Form mapping? Dojo是否支持JSON对象到dijit/form/Form映射? 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. 好吧,使用getValues()setValues()函数是可能的。

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: 可以使用适当的getter来检索相同类型的对象,例如:

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

I also made an example using JSFiddle . 我还使用JSFiddle进行了示例。

DOJO plugin is deprecated in struts 2.1.x - http://struts.apache.org/release/2.1.x/docs/ajax-tags.html 道场插件弃用支柱的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 更好地使用JSON注释来形成绑定,请选中此选项- 如何使用struts2-json-plugin将JSON绑定到Struts2中的Java对象

Dojo has an MVC package, used for binding elemnts to JSON values. Dojo有一个MVC包,用于将元素绑定到JSON值。 The dojo/mvc/at does the widget to json binding dojo / mvc / at将小部件与json绑定

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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