奇怪的jQuery XML问题 [英] Strange jQuery XML problem
问题描述
我在XML文档中有一个引号列表。每个报价都包含如下:
I have a list of quotes in an XML document. Each quote is wrapped like this:
<Item>
<Quote>This is a quote!</Quote>
<Source>-- this is the Source of the Quote!</Source>
</Item>
这是jQuery:
var html = '';
var tmpl = '<li class=""><p class="quote">__quote</p><p class="source">__source</p></li>';
$(quoteObj).find('Item').each(function(){
$that = $(this);
var _quote = $that.children('Quote').text();
var _source = $that.children('Source').text();
var qhtml = tmpl.replace('__quote', _quote).replace('__source', _source);
html += qhtml;
});
return html;
在最终产品中, QUOTES
是所有,但 SOURCES
不是。我不能为我的生活找出原因。在我面前有什么我看不到的东西?
In the end product, the QUOTES
are all there, but the SOURCES
aren't. I can't for the life of me figure out why. What's right in front of me that I can't see?
回答评论的其他信息:
- XML格式正确,我在上面进行了更改。
- 我添加了
var tmpl
行来显示我在循环中取代了什么。__ quote
正在被替换,并且__ source
至少被采取行动,因为第二个< p>
是空的,而不是包含字符串。 - 我检查了从AJAX调用返回的实际XML,它就在那里,应该如此。
- The XML is properly formed, and I changed it above.
- I added the
var tmpl
line to show what I'm replacing in the loop. The__quote
is being replaced, and the__source
is at least being acted upon, since the second<p>
is empty, instead of containing a string. - I have checked the actual XML coming back from the AJAX call, and it is all there, as it should be.
在我看来,这是某种与范围界定有关的问题,这个
,或者使用 .children()
方法的操作,但我仍然找不到它。
It seems to me this is some sort of issue with scoping and this
, or with the action of the .children()
method, but I still can't find it.
最后一次注意:
将XML标签案例更改为Initial Caps,它位于相关文档中。
Changed the XML tag case to Initial Caps, which it is in the document in question.
推荐答案
试过这个,我唯一需要改变的是 find
行以匹配案例XML节点,例如
Just tried this and the only thing I had to change was the find
line to match the case of the XML node, eg
$(quoteObj).find('ITEM').each( function() {
我还将 $
分配线更改为包括 var
关键字,但它在我之前工作
I did also change the $that
assignment line to include the var
keyword, but it was working before I did that
var $that = $(this);
这篇关于奇怪的jQuery XML问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!