的formatter
選項可以是一個字符串,如果它是預定義的格式化之一,但根據jqGrid docs for custom formatters:
您可以定義自己的格式化特定列。通常這是一個功能。
所以預計jqGrid的一個函數來進行傳遞。這就是爲什麼myFunction
有效,但"myFunction"
沒有。總之,解決你的問題,你需要輸出的代碼:
"formatter": myFunction
要進入深一點,你可以在jqGrid的源文件
grid.base.js的格式直接使用的功能中所看到的,但如果一個字符串通過了字符串傳遞給
$.fn.fmatter
:
formatter = function (rowId, cellval , colpos, rwdat, _act){
var cm = ts.p.colModel[colpos],v;
if(typeof cm.formatter !== 'undefined') {
var opts= {rowId: rowId, colModel:cm, gid:ts.p.id, pos:colpos };
if($.isFunction(cm.formatter)) {
v = cm.formatter.call(ts,cellval,opts,rwdat,_act);
} else if($.fmatter){
v = $.fn.fmatter(cm.formatter, cellval,opts, rwdat, _act);
} else {
v = cellVal(cellval);
}
} else {
v = cellVal(cellval);
}
return v;
},
如果該功能已不存在於jquery.fmatter.js那麼我希望當電網試圖用它來發生錯誤。
你的問題是有點難以遵循,但如果您有格式化的問題,你應該能夠僅僅把它定義爲'「格式化」:myFunction'然後'當電網需要myFunction'將被調用格式化該列。但是你提到'eval' ...這裏還有其他的東西嗎? –
opts在HashMap中。 Map opts = new HashMap (); opts.put(「formatter」,「myFunction」); opts.put(「index」,「」); opts.put(「name」,「」); 然後,用於colModel的opts格式化程序: {「formatter」:「myFunction」,「index」:「」,「name」:「」} –
user1404404
這是js文件上的功能。 函數myFunction的(cellvalue,期權,rowObject){ \t返回 「Click here」; } 我不爲什麼不jqGrid的調用myFunction的? 隨着我得到選擇,上面的一個節目,並把它的工作reall文件; 這裏工作 colModel:[ \t ... \t { 「格式化」:myFunction的, 「指數」: 「」, 「名」: 「」} \t //工作 ], 這裏不行 colModel: [ \t ... \t { 「格式化」: 「myFunction的」, 「指數」: 「」, 「名」: 「」} \t //注意:在真正的文件字符串沒有工作過myFunction的。 ], – user1404404