gpt4 book ai didi

javascript - dojo/dijit ContentPane 设置内容

转载 作者:行者123 更新时间:2023-11-29 22:41:33 25 4
gpt4 key购买 nike

我正在尝试将通过 dojo.XHRGet 检索到的一些 XML 附加到 dijit.layout.ContentPane。在 Firefox (3.6) 中一切正常,但在 Chrome 中,我只会在特定的 ContentPane 中返回“未定义”。

我的代码看起来像这样:

var cp = dijit.byId("mapDetailsPane");
cp.destroyDescendants(); // there are some existing Widgets/content I want to clear
// and replace with the new content

var xhrData = {
url : "getsomexml.php",
handleAs: "xml",
preventCache: true,
failOk: true
};

var deferred = new dojo.xhrGet(xhrData);
deferred.addCallback(function(data) {
console.log(data.firstChild); // get a DOM object in both Firebug
// and Chrome Dev Tools
cp.attr("content",data.firstChild); // get the XML appended to the doc in Firefox,
// but "undefined" in Chrome
});

因为在这两种浏览器中我都返回了一个有效的 Document 对象,我知道 XHRGet 工作正常,但内容的设置方式似乎存在某种差异。有没有更好的方法来处理请求的返回数据?

有一个查看我的 XML 的请求,所以这是其中的一部分...

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
version="1.1" width="672" height="1674">
<defs>
<style type="text/css">
<![CDATA[ ...bunch of CSS...
]]>
</style>
<marker refX="0" refY="0" orient="auto" id="A00End" style="overflow: visible;">
...bunch more defs...
</defs>
<g id="endpoints">
...bunch of SVG with a some...
<a xlink:href="javascript:gotoLogLine(16423,55);" xlink:type="simple">...more svg...</a>
</g>
</svg>

我已经通过 WC3 XML 验证程序运行输出 XML 以验证它是否有效。正如我之前所说,适用于 FireFox 3.6。我在 Safari 上试过了,我得到了同样的“未定义”,所以它似乎与 Webkit 有关。

最佳答案

cp.containerNode.appendChild(data.firstChild) 有效吗?将 ContentPane 视为可以接受任意 XML 节点的通用容器可能要求过高。它的主要用例是——而且一直都是——注入(inject) HTML。并不是说它不能工作,但它是一个在这个小部件中没有得到很好探索的极端情况。

关于javascript - dojo/dijit ContentPane 设置内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2402900/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com