stackoverflow newbie here,所以我希望你能通过帮助我解决问题给我一个温暖的welcoe。我发现了几个与此类似的问题和答案,但没有一个正是我所需要的。 我通过AJAX(jQuery的),我想能够拉动一些XML使用复选框等来筛选类似这样的网站: http://www.worldmarket.com/giftfinder/index.jsp通过jquery以复选框格式过滤XML
XML是不是最好的方式格式化(我有无法控制),以及类似于这样对我拉中的每个元素:
<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()添加一些东西,这些东西说的是精细的元素WHERE tags = ...(我知道这是漂流到SQL的土地上,但是...) 无论如何,任何帮助或方向将大受赞赏。 在此先感谢!
再次感谢您的帮助。
我试过使用.has,到目前为止还不能真正使它工作。哪怕只是用我上面列出的虚拟数据测试它在一般情况下,这是行不通的:
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);
对不起,我想我只是不得到的东西。 谢谢。
不要忘记,以纪念我的答案,如果它帮助你。 – Andir 2010-07-13 02:27:04