从jqGrid格式化程序的JSON双引号中删除

时间:2014-09-13 11:45:33

标签: javascript jquery json jqgrid

我从webservice的JSON响应中生成colModel,这些数据直接绑定到colModel,这非常有效。

我遇到的问题是以某种方式删除或使jqGrid理解" formatter"中的值。是一个函数,我知道jqGrid期望它没有双引号,但我不知道如何从JSON中删除双引号,所以当我将JSON加载到colModel时,实际上调用了函数。 使用双引号它不起作用。 我到处寻找了一天,无法找到解决方案(或删除双qoutes或使jqGrid理解格式化程序中的值是一个函数来调用。

目前我有:

 {"editable":true,"edittype":"checkbox","index":"invite","jsonmap":"invite","key":false,"name":"invite","label":"Invite","formatter":**"myfunction"**,"resizable":true,"hidden":false,"search":false,"sortable":true,"width":50,"sorttype":0,"align":"left"},

需要:

 {"editable":true,"edittype":"checkbox","index":"invite","jsonmap":"invite","key":false,"name":"invite","label":"Invite","formatter":**myfunction**,"resizable":true,"hidden":false,"search":false,"sortable":true,"width":50,"sorttype":0,"align":"left"},

任何有关这方面的帮助都会很好! )

1 个答案:

答案 0 :(得分:0)

JSON不允许您引用函数。因此,您应该使用字符串,例如"formatter": "myFormatter"。要使此类代码有效,您应该将已定义的myFormatter扩展为$.fn.fmatter对象的方法:

$.extend($.fn.fmatter, {
    myFormatter: function (cellValue, options) {
        // ...
    }
});

请查看the cod e或this one作为格式化程序注册的示例。

相关问题