jQuery 如何动态构建列表视图 JQueryMobile

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8753783/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 10:59:32  来源:igfitidea点击:

How to dynamically build list view JQueryMobile

jqueryjquery-mobile

提问by shyamshyre

I need to dynamically add a list view. I am able to build the list view dynamically but i am appending

我需要动态添加一个列表视图。我能够动态构建列表视图,但我正在附加

  • to hard coded tag in the below html snippet.

    The HTML code snippet.
    <ul id="mymenu" data-role="listview" >
    </ul>
    
    Jquery Code Snippet.
    $("#accpmenu").append('<li><a href='+ "#" + ' id="a"  "> <img src="letterheader.png" >'+ this.textContent + '  </a> </li>'); 
    

    I even want to dynamically build the and then append

  • 到下面的 html 片段中的硬编码标签。

    The HTML code snippet.
    <ul id="mymenu" data-role="listview" >
    </ul>
    
    Jquery Code Snippet.
    $("#accpmenu").append('<li><a href='+ "#" + ' id="a"  "> <img src="letterheader.png" >'+ this.textContent + '  </a> </li>'); 
    

    我什至想动态构建然后附加

  • Please help me in achieving this.

    Thanks Shyam

  • 请帮助我实现这一目标。

    谢谢 夏姆

  • 回答by mram888

    After appending you must refresh the list:

    附加后,您必须刷新列表:

      $("#mymenu").listview("refresh");
    

    回答by user700284

    Here is an example which creates a list dynamically.

    这是一个动态创建列表的示例。

    http://jsfiddle.net/SuSpv/

    http://jsfiddle.net/SuSpv/

    Let me know if that helps.

    如果这有帮助,请告诉我。

    回答by Arun

    I have use below code working fine to me

    我使用下面的代码对我来说工作正常

    Dynamic Listview

    动态列表视图

    <script>
    
    
    var myArray = ["Arun", "kumar", "Mani", "Vimal", "Vinoth"];
    
    $.each(myArray, function(index, value){
    
        console.log("INDEX: " + index + " VALUE: " + value);
    
    
    });
    
    
             var output = [];
    
        for (var i = 0; i <myArray.length; i++) {
    
    
           output.push('<li><img src="img/img_help.png">' + myArray[i] +'</li>');
    
        }
    
         $('#coursemates').append(output.join('')).listview('refresh');
    
         $("#coursemates").listview("refresh");
    
    </script>