YUI 2.5. Populating a dropdown from XML

你离开我真会死。 提交于 2019-12-13 05:07:20

问题


Currently editing an application built using YUI 2.5 and Perl. I need to populate a dropdown from an xml file, and only specific rows are to be used depending on the attributes of the node. Unfortunately, there isn't the DropdownCellEditor widget in YUI 2.5 (as far as I'm aware, this didn't come in until 2.6(?)). Does anyone have any ideas?

I'm thinking I should probably just update YUI as there seems to be a lot of useful functionality missing in this very old version. The code the original developer is using is very convoluted, so this is my last try! Any advice would be greatly appreciated...


回答1:


I haven't used YUI2 for quite some time now, but I had built an example back then:

http://www.satyam.com.ar/yui/#dynamicDropdown

I hope it still works.




回答2:


Just incase anyone else is stuck with something similar, I managed to populate the dropdown from an XML file as follows:

//create function to read XML
function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
}
else
{
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET",dname,false);
xhttp.send();
return xhttp.responseXML;
} 

// load xml file
xmlDoc=loadXMLDoc('xmlsource.asp' + gameid);

teamnames =[];
var teams = xmlDoc.getElementsByTagName("hometeams");
for (var i = 0; i < teams.length; i++) {

var hname  = teams[i].getAttribute("name");
teamsnames.push(hname);
}

Then later on in column definitions:

var eventColumnDefs = [
{key:"teamname", sortable:true, editor:"dropdown", editorOptions:{dropdownOptions:teamnames}}
];

I hope this helps someone. Thank you Satyam for your help on this and my other question. =]



来源:https://stackoverflow.com/questions/16542001/yui-2-5-populating-a-dropdown-from-xml

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