Dojo and javascript: lightweight tooltip in onclick on anchor tab

两盒软妹~` 提交于 2019-12-25 04:15:25

问题


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+'&nbsp;&nbsp;<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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!