Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery mobile 如何在listview单击时将动态创建的数据放入对话框_Jquery Mobile - Fatal编程技术网

Jquery mobile 如何在listview单击时将动态创建的数据放入对话框

Jquery mobile 如何在listview单击时将动态创建的数据放入对话框,jquery-mobile,Jquery Mobile,我动态创建了一个列表视图,但我不知道如何从所选列表中获取数据以显示在对话框中。我试过几种方法,但都失败了。我唯一正确的方法就是单击调用对话框 我想在弹出对话框中显示整个消息 我的代码 <body> <div data-role="page" id="messages"> <div data-theme="a" data-role="header"> <a data-role="button" hre

我动态创建了一个列表视图,但我不知道如何从所选列表中获取数据以显示在对话框中。我试过几种方法,但都失败了。我唯一正确的方法就是单击调用对话框

我想在弹出对话框中显示整个消息

我的代码

<body>
   <div data-role="page" id="messages">
            <div data-theme="a" data-role="header">
             <a data-role="button" href="index.html" data-transition="slide"
                data-icon="arrow-l" data-iconpos="left" class="ui-btn-left">
                    Back
                </a>
            <a href="#" onclick="window.location.reload()" data-icon="back" data-iconpos="notext">Refresh</a>
                <h3>
                   Alerts
                </h3>
            </div>
            <div data-role="content">           
            <script type="text/javascript">
                            $(document).on("pagebeforeshow", "#messages", function() {
                            var uid = $.cookies.get( 'uid' );
                            if(uid == null){
                                 $.mobile.changePage( "account-login.html", { transition: "slide"} );}
                                     $(function(){
                                $.getJSON("ajaxResponder.php?method=messages",function(data){

                                            var htmlString ="";

                                                $.each(data.messages,function(index,item){
                                                htmlString +='<li data-name='+item.msgid+'><a href="#">'+
                                                                '<h3 class="topic">'+item.subject+'</h3>' + 
                                                                '<p>From: '+item.sender+'</p>' +
                                                                '<p>Date: '+item.added+'</p>' +
                                                                '<p>'+ item.message +'</p></a></li>' ;

                                                });

                                                $('#list').html(htmlString);
                                                $('#list').listview('refresh');
                                            });  
                            });
                           });     
                        </script>
                <ul id="list"  data-role="listview" data-theme="d"></ul>
        </div>
        <script>
 $('#list').on('click', 'li', function() {
    $.mobile.changePage("#dialog", {
        role: "dialog"
    }); 
     });    
        </script>
</div>
<div data-role="page" data-rel="dialog" id="dialog" data-theme="c" data-close-btn="right">
    <div data-role="header" data-position="fixed" data-theme="b">
         <h1>New values added!</h1>

    </div>
    hello
<!-- display item.message here -->
    </ul>
</div>      

</body>
</html>

警报
$(文档)。在(“pagebeforeshow”,“消息”,函数()上){
var uid=$.cookies.get('uid');
如果(uid==null){
$.mobile.changePage(“account login.html”,{transition:“slide”});}
$(函数(){
$.getJSON(“ajaxResponder.php?method=messages”,函数(数据){
var htmlString=“”;
$.each(数据、消息、函数(索引、项){
htmlString+=';
});
$('#list').html(htmlString);
$('#list')。列表视图('refresh');
});  
});
});     
    $('#list')。在('click','li',function()上{ $.mobile.changePage(#对话框){ 角色:“对话” }); }); 新增价值! 你好
    已更新 根据您的注释,若要读取父元素的任何数据,请使用
    .closest()


    只需阅读


    这很好,但是如果我只想传递item.message,我能不能在另一个中传递它,但用一个类隐藏?你的意思是
    '+item.message+'

    ?是的,我想能够将消息和id发送到对话框(2个变量),然后创建一个删除/读取按钮,并在关闭时对其执行操作,而不是再次请求数据。如果数据名称符合您的要求,请检查演示,我已经更新了它。只有前两项。@StevenKinnear welcome;)我已经相应地更新了我的答案。
    $('#list').on('click', 'li a', function () {
     var text = $(this).closest('li').attr('data-name');
     $('#msg').empty();
     $('#msg').append(text);
     $.mobile.changePage("#dialog", {
        role: "dialog"
     });
    });