JQueryMobile filtering a XMLhttprequest
JQueryMobile filtering a XMLhttprequest
我很难让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>');
您没有在创建表后初始化jQuery Mobile小部件(表和过滤器)。下面是如何做的一个例子。
给定一个带有过滤器输入和表空容器的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"
的表,继续创建head和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
相关文章:
- XMLHttpRequest未返回值-状态202
- XMLHttpRequest在移动设备上的chrome上不起作用
- AJAX简单错误.XMLHttpRequest无法加载http://localhost/mpl/getPage.php.
- 检查xmlhttprequest问题的消息
- 主线程上的同步XMLHttpRequest已弃用
- 如何定期发出xmlhttprequest
- javascript第三个XMLHttpRequest被拒绝.但前两个是允许的
- 上传带有XMLHttprequest的文件-多部分/表单数据中缺少边界
- 对象#<XMLHttpRequest>没有方法'完成'
- 在XMLHttpRequest之后重新初始化jQuery
- 如何将GreaseMonkey中的XMLHttpRequest延迟到目标页面加载完成
- Javascript XMLHttpRequest——只有第一个POST请求有效
- XMLHttpRequest - difference between Chrome & Firefox
- IE上的新XMLHttpRequest()出现JS Ajax未指定错误
- 非常简单的XMLHttpRequest不起作用
- 如何使用XMLHttpRequest下载文件
- XMLHttpRequest在$.ajax工作的地方给出了CORS错误
- XMLHttpRequest.open()AJAX中的参数url
- XMLHTTPRequest脚本中没有internet连接和超时
- 为什么当async标志设置为false时,xmlhttprequest中的代码可以工作,而当它设置为true时却不能工作