JavaScriptSerializer 用于序列化 JavaScript 函数名称
我在项目中使用 Flexigrid 在网格工具栏上添加一个按钮,我可以使用如下代码:
...
"buttons":[
{"name":"Modifica","bclass":"edit","onpress":"doCommand"},
{"name":"Elimina","bclass":"delete","onpress":"doCommand"}
],
...
无论如何,“onpress”属性应包含对 js 回调的引用,因此该字段不应包含在引号内。
我正在使用 JavaScriptSerializer 类(在 System.Web.Script.Serialization 命名空间中)来进行序列化。
我必须如何声明变量才能使 JavaScriptSerializer 像这样序列化?
...
"buttons":[
{"name":"Modifica","bclass":"edit","onpress":doCommand},
{"name":"Elimina","bclass":"delete","onpress":doCommand}
],
...
感谢您的帮助!
I am using Flexigrid in my project to add a button on the grid toolbar I can use code like this:
...
"buttons":[
{"name":"Modifica","bclass":"edit","onpress":"doCommand"},
{"name":"Elimina","bclass":"delete","onpress":"doCommand"}
],
...
Anyway the "onpress" attribute shall contain a reference to a js callback and so this field shall not be enclosed within quotation marks.
I am using the class JavaScriptSerializer (in the System.Web.Script.Serialization namespace) to do the serialization.
How I have to declare the variable to make JavaScriptSerializer serialize like this?
...
"buttons":[
{"name":"Modifica","bclass":"edit","onpress":doCommand},
{"name":"Elimina","bclass":"delete","onpress":doCommand}
],
...
Thanks for helping!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这招怎么样?
How about this trick ?
据我所知,没有一种使用 .NET 序列化程序执行此操作的本机方法,但您可以在客户端执行以下代码,将
onpress
JSON 字符串转换为回调...To the best of my knowledge, there is not a native way to do this with the .NET serializer, but you could execute the following code on the client-side to turn the
onpress
JSON string into a callback...JavaScriptSerializer旨在序列化为JSON,而JSON不能表示函数;它也不能引用先前定义的变量。所以我不相信这是可能的。
JavaScriptSerializer is meant for serializing to JSON, and JSON can not represent functions; it also can't refer to previously defined variables. So I don't believe this is possible.
您可以将函数名称存储为字符串
You can store the function name as a string