我正在使用jqGrid创建一个网站,我正在尝试使用cellattr函数将第一列中每个单元格的'title'属性设置为xml文件中定义的标记。我已经粘贴在我正在使用的javascript下面尝试完成此操作,下面我已经包含了一个我正在使用单个记录的xml文件的示例。但是,目前它将title属性设置为'undefined'。我在cellattr函数中尝试了各种return语句,包括:
return 'title="' + onHoverText + '"';
return 'title="' + rawObject.onHoverText + '"';
return 'title="' + cm[onHoverText] + '"';
没有成功。这是完整的JavaScript代码:
Query(document).ready(function() {
jQuery("#list").jqGrid({
xmlreader: {
root:"rows",
row:"row",
repeatitems: false,
onHoverText:"onHoverText"
},
url: "data.xml",
datatype: "xml",
mtype: "GET",
colNames: ["","Bisulfite seq","OxBisulfite seq","Genome seq","H3K27ac","H3K27me3","H3K36me3","H3K4me1","H3K4me3","H3K9ac","H3K9me3","Input DNA Control","mRNA seq","miRNA seq","MRE seq","MeDIP seq"],
colModel: [ { name: "", width: 360, classes: 'ui-state-default', cellattr: function (rowId, val, rawObject, cm, rdata) {
return 'title="' + onHoverText + '"';
}},
{ name: "bisulfite_seq", width: 25, align: "center", classes: "data_cell", sortable: false, cellattr: cellattr_func0 },
{ name: "oxbisulfite_seq", width: 25, align: "center", classes: "data_cell", sortable: false, cellattr: cellattr_func1 },
{ name: "genome_seq", width: 25, align: "center", classes: "data_cell", sortable: false, cellattr: cellattr_func2 },
{ name: "h3k27ac", width: 25, align: "center", classes: "data_cell", sortable: false, cellattr: cellattr_func3 },
{ name: "h3k27me3", width: 25, align: "center", classes: "data_cell", sortable: false, cellattr: cellattr_func4 },
{ name: "h3k36me3", width: 25, align: "center", classes: "data_cell", sortable: false, cellattr: cellattr_func5 },
{ name: "h3k4me1", width: 25, align: "center", classes: "data_cell", sortable: false, cellattr: cellattr_func6 },
{ name: "h3k4me3", width: 25, align: "center", classes: "data_cell", sortable: false, cellattr: cellattr_func7 },
{ name: "h3k9ac", width: 25, align: "center", classes: "data_cell", sortable: false, cellattr: cellattr_func8 },
{ name: "h3k9me3", width: 25, align: "center", classes: "data_cell", sortable: false, cellattr: cellattr_func9 },
{ name: "input_dna_control", width: 25, align: "center", classes: "data_cell", sortable: false, cellattr: cellattr_func10 },
{ name: "mrna_seq", width: 25, align: "center", classes: "data_cell", sortable: false, cellattr: cellattr_func11 },
{ name: "mirna_seq", width: 25, align: "center", classes: "data_cell", sortable: false, cellattr: cellattr_func12 },
{ name: "mre_seq", width: 25, align: "center", classes: "data_cell", sortable: false, cellattr: cellattr_func13 },
{ name: "medip_seq", width: 25, align: "center", classes: "data_cell", sortable: false, cellattr: cellattr_func14 },
],xmlreader: {
root:"rows",
row:"row",
repeatitems: false,
onHoverText:"onHoverText"
},
treeGrid: true,
treeGridModel:'adjacency',
pager: "",
rowNum: 30,
rowList: [30, 60, 90],
sortname: "invid",
sortorder: "desc",
viewrecords: true,
gridview: true,
autoencode: true,
caption: "Epigenomic Data Grid - hg19",
height: "100%",
cellEdit: true,
onCellSelect: function(rowid, iCol, cellcontent, e) {
update_selection(cellcontent, e);
}
});
});
XML文件看起来像这样
<?xml version='1.0' encoding='utf-8'?>
<rows>
<page>"page"</page>
<total>TP</total>
<records>99</records>
<row id='0'>
<onHoverText> this is foo </onHoverText>
<cell>d<![CDATA[ Blood]]></cell>
<cell class="has_data in_progress"></cell>
<cell class="has_data in_progress"></cell>
<cell class="has_data CEMT level_0">4</cell>
<cell class="has_data CEMT level_0">11</cell>
<cell class="has_data CEMT level_0">11</cell>
<cell class="has_data CEMT level_0">12</cell>
<cell class="has_data CEMT level_0">12</cell>
<cell class="has_data CEMT level_0">12</cell>
<cell/>
<cell class="has_data CEMT level_0">11</cell>
<cell class="has_data CEMT level_0">11</cell>
<cell class="has_data CEMT level_0">4</cell>
<cell class="has_data CEMT level_0">4</cell>
<cell/>
<cell/>
<cell>0</cell>
<cell></cell>
<cell>false</cell>
<cell>true</cell>
<cell>true</cell>
</row>
</rows>
我的印象是,一旦定义了xmlreader,就有一个解析xml的函数,但我找不到它。我将不胜感激任何帮助。
注意:如果有人想查看网站示例,您可以在以下位置查看:http://www.bcgsc.ca/downloads/bdavis/tempsite/
干杯, 布拉德戴维斯
答案 0 :(得分:1)
我正确理解您的问题,您可以使用$("onHoverText", rawObject).text()
内的cellattr
来访问数据。 The old answer提供了cellattr
与datatype: "xml"
一起使用的示例。
一般情况下,我建议尽可能使用datatype: "json"
代替datatype: "json"
。
更新:The demo使用$("onHoverText", rawObject).text()
并在<onHoverText> this is foo </onHoverText>
来自第一列的单元格上生成正确的工具提示: