jQuery   发布时间:2022-04-19  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了动态地将元素附加到jQuery Mobile ListView大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想动态地将通过JSOn格式的URL接收的数据附加到我的listview.但我无法弄清楚它是如何工作的.

移动网站以下列格式检索对象:

[
    {"id":1,"start":"2011-10-29T13:15:00.000+10:00","end":"2011-10-29T14:15:00.000+10:00","title":"MeeTing"}
]

在.html中我有一个表视图一个函数,我尝试附加接收的数据.我只展示身体.

<body>
       <div>   
            <ul id="listview">
                <script>$.getJSON("url",function(data){
                    $.each(data,function(i,data){
                        i.title.appendTo("#listview");
                    });});</script> 
            </ul>
        </div>
</body>

可能它很容易,但我是网络编程的新手,我无法弄清楚我应该如何追加检索到的数据.

有人可以帮帮我吗?

@H_502_15@解决方法
//make AJAX call to url
$.getJSON("url",function(data){

    //declare a variable with which to build our output (it's best to buffer output and only do one append at the end since DOM manipulation is cpu expensivE)
    var output = '';

    //iterate through the data (we Could also get rid of the jQuery here by using `for (key in data) {
    $.each(data,function(index,value){

        //add each value to the output buffer (we also have access to the other properties of this object: id,start,and end)
        output += '<li>' + value.title + '</li>';
    });

    //Now append the buffered output to the listview and either refresh the listview or create it (meaning have jQuery Mobile style the list)
    $('#listview').append(output).listview('refresh');//or if the listview has yet to be initialized,use `.trigger('create');` instead of `.listview('refresh');`
});

这是上述解决方案的一个小问题(还有一个使用for(){}而不是$.each()的例子:http://jsfiddle.net/VqULm/

大佬总结

以上是大佬教程为你收集整理的动态地将元素附加到jQuery Mobile ListView全部内容,希望文章能够帮你解决动态地将元素附加到jQuery Mobile ListView所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。