jQuery 在 jqGrid 自定义格式化程序中访问行数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4036751/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Access row data in jqGrid custom formatter
提问by Marcus Leon
We have a grid with datatype json.
我们有一个数据类型为 json 的网格。
We have the following custom formatter:
我们有以下自定义格式化程序:
function opsFormatter (cellvalue, options, rowObject){
'<a title=MA href=javascript:showDialog(' + rowObject[5] + ')>MA<a>' + ' ';
}
Instead of rowObject[5]
is there any object notation where we can specify the actual column name ("account")? Ie: rowObject.account
.
取而代之的rowObject[5]
是有没有对象的符号,我们可以指定实际的列名(“帐户”)?即:rowObject.account
。
This is the grid definition:
这是网格定义:
$("#grid-pos").jqGrid({
colNames:['Product', 'Type','Expiry', 'Put Call', 'Strike', 'Account','Long','Short', 'Open Qty', 'LTD', 'Operations'],
colModel :[
{name:'product', index:'product', width:75, sortable:false},
{name:'type', index:'type', width:50, align:'right', sortable:false},
{name:'expiry', index:'expiry', width:60, align:'right',stype:'select', searchoptions:{dataUrl:'expiry_select.htm'}, sortable:false},
{name:'putCall', index:'putCall', width:65, sortable:false},
{name:'strike', index:'strike', sorttype: 'float', width:70, sortable:false},
{name:'account', index:'account', width:70, sortable:false},
{name:'long', index:'long', width:55, align:'right', sortable:false},
{name:'short', index:'short', width:55, align:'right', sortable:false},
{name: 'openQty', index:'openQty', width:80, align:'center', formatter:closeoutFormatter, sortable:false},
{name:'LTD', index:'LTD', width:65, align:'right', sortable:false},
{index:'operations', width:105, title:false, align: 'center', formatter:opsFormatter, sortable:false}
],
pager: '#div-pos-pager',
caption: 'Positions'
});
??
??
回答by Oleg
It seems for me absolute correct behavior. The value of the parameter rowObject
is objecthaving properties with the same names as defined in the 'name' property of the colModel
. The property account
is one from there. I suppose that the misunderstanding come from the following part of the documentation of the custom formatter:
对我来说,这似乎是绝对正确的行为。该参数的值rowObject
是对象与作为的“名称”属性中定义的相同名称具有属性colModel
。该属性account
是从那里之一。我想误解来自自定义格式化程序文档的以下部分:
rowObject - is a row data represented in the format determined from datatype option. ... If we have datatype: json/jsonstring - the rowObject is array, provided according to the rules from jsonReader
rowObject - 是以从数据类型选项确定的格式表示的行数据。...如果我们有数据类型:json/jsonstring - rowObject 是数组,根据 jsonReader 的规则提供
Probably the word arrayfollows to misunderstanding. In JavaScript rowObject.account
can be used as rowObject["account"]
, but one can't use rowObject[5]
to access the account
property of rowObject
. It is just not clear written sentence in the documentation. If you are a native English speaker you can reformulate the text so that it will has no misunderstandings. The documentation is wiki and any person can change any text.
可能词数组跟随误解。在 JavaScriptrowObject.account
中可以用作rowObject["account"]
,但不能用于rowObject[5]
访问 的account
属性rowObject
。只是文档中没有明确的书面句子。如果您的母语是英语,则可以重新编写文本,以免引起误解。文档是维基,任何人都可以更改任何文本。
回答by Erdi Gürbüz
You can get with this code for second index
您可以使用此代码获取第二个索引
rowObject.childNodes[2].textContent