我已经使用AJAX其中我打电话到我的网站的DOM下面的XML文档的DOM元素的独特的内容:jQuery的:过滤器/获取/选择
<product>
<title>DVR 4 CH</title>
<category>DVR</category>
</product>
<product>
<title>DVR 8 CH</title>
<category>DVR</category>
</product>
<product>
<title>Infrared PIR motion sensor</title>
<category>Alarms</category>
</product>
<product>
<title>Bullet Camera 1000 TVL</title>
<category>Bullet Cameras</category>
</product>
如何过滤/获取/选择具有独特HTML <category>
元素的数组内容?。如果您查看代码,您会看到有四个<category>
元素:2个DVR,1个警报,1个子弹头摄像机。
我想只有<category>DVR</category>
,<category>Alarms</category>
和<category>Bullet Cameras</category>
(过滤重复的DVR类)。
jQuery有所述$.uniqueSort功能,该滤波器滤除重复DOM元素。
我需要的不是这样。我需要过滤那些内部HTML内容是唯一/不同的内容。下面是我使用的代码(加上AJAX),它显示在控制台中的四个要素,包括复制:
var request = $.ajax({
url: "../../../resources/xml/lista-de-precios/common/prices_database.xml",
dataType: 'xml',
cache: 'false',
method: 'GET',
async: 'true'
});
request.done(function() {
getAndUseCategoriesAndLinks(request);
});
function getAndUseCategoriesAndLinks(xml) {
var xmlDoc = xml.responseXML,
xml = $(xmlDoc),
category = xml.find("category");
var each_element_new = $(category).each(function() {
console.log($(this).text());
$("ul.categories-list").append('<li><a href="#">' + $(this).text() + '</a></li>');
});
}
你可以有一个回调Fn键'$()。过滤器()'? – Garfield
看看这个:http://stackoverflow.com/questions/2232458/how-to-use-jquery-to-select-xml-nodes-with-unique-text-content –