JQueryMobile过滤XMLhttprequest

时间:2014-03-26 19:08:21

标签: javascript xml jquery-mobile

我很难让JQueryMobile过滤器功能处理我正在使用的脚本。

我创建了一个简单的xmlhttp请求,用于从包含175个条目和4列的XML文件中收集数据。输出没问题。现在我不想在这张桌子里面过滤。但是当它挂起它没有任何效果。

感谢任何帮助

<script type="text/javascript">

xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","Issue.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;


    document.write('<table border="1" cellspacing="1" cellpadding="5">')
    var Asset = xmlDoc.getElementsByTagName("Attribute");

     for (x = 0; x <= Asset.length; x++)    //Asset.length
            {
            document.write("<tr>");
              document.write("<td>" + xmlDoc.getElementsByName("Number")[x].childNodes[0].nodeValue)  + "</td>"; 
              document.write("<td>" + xmlDoc.getElementsByName("Name")[x].childNodes[0].nodeValue)  + "</td>"; 
              document.write("<td>" + xmlDoc.getElementsByName("Address")[x].childNodes[0].nodeValue)  + "</td>"; 
              document.write("<td>" + xmlDoc.getElementsByName("Phone")[x].childNodes[0].nodeValue)  + "</td>"; 
            document.write("</tr>");
            }

    document.write("</table>");
  </script>

XML:

<?xml version="1.0" encoding="UTF-8"?>
<Assets pageSize="2222222" pageStart="0" total="175">
<Asset href="www.home1.com">
    <Attribute name="Number">123123123</Attribute>
    <Attribute name="Name">asdqweqweqwe</Attribute>
    <Attribute name="Address">dsffdfsdfdasfsda</Attribute>
    <Attribute name="Phone">123123123</Attribute>
</Asset>
<Asset href="www.home2.com">
    <Attribute name="Number">4344433</Attribute>
    <Attribute name="Name">ssssss</Attribute>
    <Attribute name="Address">ddddd</Attribute>
    <Attribute name="Phone">6666666</Attribute>
</Asset>
</Asset>

工作表标题:

    document.write('<table data-role="table" data-filter="true" data-input="#filterTable-input" id="thetable" class="ui-responsive table-stroke">');
    document.write('<thead><tr><th>Number</th><th>Name</th><th>Custom</th><th>Owner</th></tr></thead>');
    document.write('<tbody>');

1 个答案:

答案 0 :(得分:0)

创建表后,您没有初始化jQuery Mobile小部件(table和filterable)。这是一个如何做的例子。

给定一个带有过滤器输入的jQM页面和该表的空容器:

<div data-role="page" id="page1">
    <div data-role="header" data-position="fixed">
         <h1>My page</h1> 
    </div>
    <div role="main" class="ui-content">
        <form>
            <input id="filterTable-input" data-type="search" />
        </form>
        <div id="tableContainer">
        </div>
    </div>
</div>

您的脚本将使用data-filter="true"data-input="#filterTable-input"创建表,继续创建THEAD和TBODY部分并使用您的XML填充行。将创建的表附加到空容器后,使用.table().filterable()初始化表和可过滤的小部件:

$(document).on("pagecreate", "#page1", function(){      
    var thetable = '<table data-role="table" data-filter="true" data-input="#filterTable-input" id="thetable" class="ui-responsive table-stroke">';    
    thetable += '<thead><tr><th>Number</th><th>Name</th><th>Address</th><th>Address</th></tr></thead>';
    thetable += '<tbody>';
    for (x = 0; x <= 175; x++)  {
        thetable += '<tr>';
        thetable += '<td>' + x + 'a</td>'
        thetable += '<td>' + x + 'b</td>'
        thetable += '<td>' + x + 'c</td>'
        thetable += '<td>' + x + 'd</td>'
        thetable += '</tr>';
    }
    thetable += '</tbody>';
    thetable += '</table>';

    $("#tableContainer").empty().append(thetable);    
    $("#thetable").table().filterable( );
});
  

这是 DEMO

相关问题