问题
I have a dojo datagrid and I am using a formatter that puts, among other things, link in the cell.
The formatter looks like this:
var descshort = value[1].substring(0,220);
return '<a href="'+ value[2] +'">'+value[0]+'</a><br /><div class="gridItemDescription">'+descshort+' <a href="#" onclick="showDesc();return false;">show more...</a></div>';
So you see I am only displaying the first 220 characters of value[1].
What I want to do now is show a dialog or tool tip when you click on the "show more..." link that has the complete value[1] (right now there is a showDesc(); function that does nothing). So far I got it to show up in a javascript alert by using:
onclick="javascript:alert(\' ' + value[1] + ' \');return false;"
instead of a function, but I don't like the way the alert looks, especially in IE. If I try to use a function, I can't seem to but it in a place where it will grab the value[1] data. Is there anything in Dojo or javascript I can use in the onclick event on the link to show the contents of value[1]?
回答1:
I was able to call a function for a dojo dialog and pass the values as arguments to the dojo dialog! Also it took me a while to realize that in the formatter I need to use \ to escape some of the ' characters that are used to build the returned string while inserting values as arguments.
elliotDialog = new dijit.Dialog({
title: "My Dialog",
content: "test content",
style: "width: 450px"
});
showDesc = function(layer, layer2){
// set the content of the dialog:
elliotDialog.set("title", layer2);
elliotDialog.set("content", layer);
elliotDialog.show();
};
The onclick in the formatter looks like this:
onclick="showDesc(\'' + value[1] + '\',\'' + value[0] + '\');return false;"
来源:https://stackoverflow.com/questions/18476084/dojo-and-javascript-lightweight-tooltip-in-onclick-on-anchor-tab