js高手快过来看看,也是tree的问题,有代码?

lshzfq 2004-10-21 02:43:59
页面有个<div id="deeptree" class="deeptree" CfgXMLSrc="deeptreeconfig.xml">

此<div>调用了htc文件的方法
本人对次有好几个地方一点都看不懂,请高手说明一下:

方法一:
function Init()
{
try{
var strHTML;
var objLI;

// Set up global tree accessors.
// TODO:: check that these have not been overridden by
// another consuming application.
// TODO:: encapsulate global accessors in other functionality
// as well (dtbar,searchtab,contentbar should set themselves,
// rather than doing it here)
/*
window.top.deeptree = element;
window.top.dtbar = top.frames.fraLeftFrame.frames.fraDTBar;
window.top.ulbar = top.frames.fraUserListFrame.frames.fraULBar;
window.top.toolbar = top.frames.fraToolbar.frames.fraContentBar;
window.top.content = top.frames.fraContent;
window.top.searchtab = top.frames.fraSearchTab;
window.top.leftframe = top.frames.fraLeftFrame;
window.top.rightframe = top.frames.fraRightFrame;
window.top.mainframeset = top.document.all.fstMain;
window.top.leftframeset = top.document.all.fstLeftMain;
window.top.fstleftframeset = top.document.all.fstLeft;
*/

oConfig = new Config

element.type = "container";

m_iMasterIdx = GetXML( oConfig.sTopXmlSrc , element , "deeptree" );

window.document.body.attachEvent("onkeydown",KeyDown);
}
catch(e)
{
setTimeout("Init()",3000)
}
}

element.type //这个是什么意思????
此方法中调用了一个Config
他的定义在下面:
方法二:
function Config()
{
var strCfgXMLSrc = "";
var sPath = "";
strCfgXMLSrc = element.CfgXMLSrc;
if (strCfgXMLSrc != "")
{
var objXMLDoc = new ActiveXObject("Microsoft.XMLDOM");
objXMLDoc.async = false;
objXMLDoc.load( strCfgXMLSrc );

if (objXMLDoc.xml != "")
{
var oTopXmlSrc = objXMLDoc.documentElement.selectSingleNode("//TopXMLSrc");
if ( null != oTopXmlSrc )
{
this.sTopXmlSrc = String( oTopXmlSrc.text );
}
else
{
// Error: Invalid TopXMLSrc in Config.xml
}

var oTarget = objXMLDoc.documentElement.selectSingleNode("//ContentTarget");
if ( null != oTarget )
{
this.sTarget = oTarget.text;
}
else
{
//Error: Invalid Target in Config.xml
}
}
}
}

并且他有关方法是GetXML,代码如下:
function GetXML( strXMLSrc , oEl , oElClass , oSync )
{
var aryXMLNodes;
var i = 0;
var strRetVal = "";

var iCall = fnAllocCall();
var objXMLDoc = new ActiveXObject("Microsoft.XMLDOM");
objXMLDoc.async = true;
m_aoCalls[iCall] = new CallObject( objXMLDoc , oEl , oElClass , oSync );

objXMLDoc.onreadystatechange = Function( "fnLoadComplete( " + iCall + " );" );

objXMLDoc.load( strXMLSrc );

return iCall;
}
...全文
92 5 打赏 收藏 举报
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
lshzfq 2004-10-22
  • 打赏
  • 举报
回复
哈哈...谢谢帮我顶呀.上面的兄弟,,,,,高手大概不愿意看这么长的代码吧
ouyld 2004-10-21
  • 打赏
  • 举报
回复
lshzfq 2004-10-21
  • 打赏
  • 举报
回复
怎么人呢???高手呀
lshzfq 2004-10-21
  • 打赏
  • 举报
回复
最后一个方法:
function fnLoadComplete( iIndex )
{

if( iIndex == null ) return;
var oCall = m_aoCalls[ iIndex ];
try
{
var iReadyState = oCall.oXml.readyState;
}
catch(e)
{
return;
}

if( iReadyState != 4 ) return;

if( oCall != null && oCall.oXml.xml != "" )
{
aryXMLNodes = oCall.oXml.documentElement.selectNodes("//TreeRef[@NodeXmlSrc]");
for (i = 0; i < aryXMLNodes.length; i++)
{
var objXMLDoc_Child = new ActiveXObject("Microsoft.XMLDOM");
objXMLDoc_Child.async = false;
objXMLDoc_Child.load(strRootPath + aryXMLNodes[i].getAttribute("NodeXmlSrc"));


if( null != objXMLDoc_Child.documentElement )
{
aryXMLNodes[i].parentNode.replaceChild(objXMLDoc_Child.documentElement, aryXMLNodes[i]);
}
objXMLDoc_Child = null;
}

bFixLoad = oCall.oEl.contains( objLI_Current );

if (objXSLDoc.xml != "")
{
var sHtml = oCall.oXml.transformNode( objXSLDoc );
}

if ( sHtml != null && sHtml != "" )
{
oCall.oEl.innerHTML = sHtml;
oCall.oEl.className = oCall.sElClass;
}
else
{
oCall.oEl.innerHTML = m_sTempNodeStart + m_sUnavailableText + m_sTempNodeEnd;
}

if( bFixLoad )
{
SelectNode( oCall.oEl.children[0] );
}

if( iIndex == m_iMasterIdx && m_bSyncFailed == true )
{
Sync();
}

if( oCall.oSync != null )
{
SyncAsync( oCall.oSync );
}
if( null != objLI_Current && objLI_Current.selectChild ) MoveNext();
fnDeAllocCall( iIndex );
}
else
{
oCall.oEl.innerHTML = m_sTempNodeStart + m_sUnavailableText + m_sTempNodeEnd;
}
return;

}
lshzfq 2004-10-21
  • 打赏
  • 举报
回复
其中Config对象里面的o var oTopXmlSrc = objXMLDoc.documentElement.selectSingleNode("//TopXMLSrc");

在xml是这样的: <TopXMLSrc>Tree.asp?parentcode=00</TopXMLSrc>

Tree.asp文件实际是动态输出一个xml文件

另外GetXMl里面还有两个方法是:
function fnAllocCall()
{
var iReturn = null;
for (var i = 0; i < m_iMaxCalls && m_aoCalls[m_iLastCall] != null; i++)
{
m_iLastCall = (m_iLastCall + 1) % m_iMaxCalls;
}

if (i < m_iMaxCalls)
{
iReturn = m_iLastCall;
}
return iReturn;
}
上面方法里面的变量定义如如下:
var m_iMaxCalls = 1024;
var m_aoCalls = new Array();
var m_iLastCall = 0;
var m_iMasterIdx = null;
var m_bSyncFailed = false;
另一个方法:
function CallObject( oXml , oEl , sElClass , oSync )
{
this.oXml = oXml;
this.oSync = oSync;
this.oEl = oEl;
this.sElClass = sElClass;
}

我最不明白的地方是GetXML方法里面
var iCall = fnAllocCall();
var objXMLDoc = new ActiveXObject("Microsoft.XMLDOM");
objXMLDoc.async = true;
m_aoCalls[iCall] = new CallObject( objXMLDoc , oEl , oElClass , oSync );

objXMLDoc.onreadystatechange = Function( "fnLoadComplete( " + iCall + " );" );

objXMLDoc.load( strXMLSrc );

当var iCall = fnAllocCall();第一调用的时候返回为0的时候,将会生成一个Callobject对象,放在
m_aoCalls[0]里面去,此是的Callobject对象传入的objXMLDoc参数为null值,在执行下面的objXMLDoc.onreadystatechange = Function( "fnLoadComplete( " + iCall + " );" ) 是什么意思
如果执行了fnLoadComplete(0),有什么作用?而objXMLDoc.load( strXMLSrc )只是加载xml文件,好象并不能显示



发帖
JavaScript

8.7w+

社区成员

Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
帖子事件
创建了帖子
2004-10-21 02:43
社区公告
暂无公告