我正在通过AJAX(jquery)引入一些XML,我希望能够使用复选框等进行过滤。类似于这样的网站:
http://www.worldmarket.com/giftfinder/index.jsp
<element text="something.exe" value="dev|something.exe" depth="0" lastUpdate="2010-03-09 09:50" nextUpdate="" category="Entertainment" filesize="2 MB">
<attribute key="Description" value="here is the description"></attribute>
<attribute key="Language" value="English,Russian,Ukrainian"></attribute>
<attribute key="Function" value="History, Education"></attribute>
<attribute key="Industry" value="Public Sector,Sports"></attribute>
<attribute key="Title" value="Something"></attribute>
<attribute key="Tags" value="Politics"></attribute>
</element>
因此,我可以简单地使用如下代码循环并显示网格中的所有元素:
$(this).find("element").each(function(index){
var appTitle = $(this).find("attribute[key='Title']").attr("value") || $(this).attr("text");
但我遇到的问题是过滤标签。我想在左边有几个复选框,这些复选框与XML中的不同标记(或行业或函数属性)相关联,单击时,让结果集过滤器仅显示带有这些标记的元素。
最好的方法是什么?这就好像我想在.find()中添加一些东西,上面写着fine元素,其中tags=(我知道它正漂向陆地,但是……)
无论如何,任何帮助或指导都将不胜感激。
提前谢谢!
再次感谢你的帮助。
var testThisData = '<element text="something.exe" value="dev|something.exe" depth="0" lastUpdate="2010-03-09 09:50" nextUpdate="" category="Entertainment" filesize="2 MB"><attribute key="Description" value="here is the description"></attribute><attribute key="Language" value="English,Russian,Ukrainian"></attribute><attribute key="Function" value="History, Education"></attribute><attribute key="Industry" value="Public Sector,Sports"></attribute><attribute key="Title" value="Something"></attribute><attribute key="Tags" value="Politics"></attribute></element>';
console.log($(testThisData).has("attribute[key='Language'][value~='English']").length);`
返回0,即使是这样:
console.log($(testThisData).has("attribute").length);
抱歉,我想我只是没有得到什么。
谢谢。