将Javascript代码转换为JSON,反之亦然 [英] Transform Javascript code to JSON and vice versa
问题描述
dgrid将从REST服务中填充,我的想法不仅是填充dgrid,还可以使用文本框,按钮和复选框进行自定义。
例如,这里是一个dgrid的代码,其中2列的字段不能被更改:
window.Grid = new StandardGrid ({
sort:缩写,
store:stateStore(),
列:{
缩写:'缩写',
名称:'名称'
}
},MyGrid);
该服务必须验证该人员是否为管理员,如果是,则以JSON格式发送设置以添加更多的功能,dgrid,通过更改列与:
我想以json格式发送配置代码。
我想知道这是否可行,如果是这样,怎么办?
谢谢
由于功能不是JSON的有效部分,您需要做一些数量在JSON和dgrid列插件之间进行处理。例如,在编辑器
的情况下,您可以测试每个对象以存在编辑器
属性,如果发现,当您实际从JSON中创建列结构时,应用编辑器
函数。
I'm working on a small project in which I will work with dgrid dojo, the dgrid must be customized according to the profile of the person if he's administrator or simple user. The dgrid will be filled from a REST service, and I had the idea to not only fill the dgrid but also customize it with textbox, buttons and checkbox.
For example here is the code of a dgrid with 2 columns whose fields can not be changed:
window.Grid= new StandardGrid({
sort: "abbreviation",
store: stateStore(),
columns: {
abbreviation: 'Abbreviation',
name: 'Name'
}
}, "MyGrid");
the service must verify if the person is an administrator and if so send in JSON Format the settings to add more features to dgrid, by changing "columns" with :
[ editor({
label: "Abbreviation",
field: "abbreviation",
editor: "text",
editOn: "dblclick"
}),
editor({
label: "Name",
field: "name",
editor: "text",
editOn: "dblclick"
})]
I want to send this configuration code in json format. I want to know if this is workable and if so, how? Thank you
Since functions aren't a valid part of JSON, you'd need to do some amount of processing to go between JSON and dgrid column plugins. For example, in the case of editor
, you could just test each object for presence of the editor
property, and if found, apply the editor
function around it when you actually create the column structure from your JSON.
这篇关于将Javascript代码转换为JSON,反之亦然的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!