【问题标题】:jQuery mobile adds a space after list-entriesjQuery mobile 在列表条目后添加一个空格
【发布时间】:2012-06-21 08:48:48
【问题描述】:

我从 php 中检索数据并将它们动态添加到列表视图中。如果我“即时”添加静态数据,一切看起来都很完美,但是当从 php 文件中检索数据时,jQuery Mobile 在我的列表条目之后添加了一个空格。有已知问题吗?!

我的 js 文件看起来像:

        userda = '';
    $.ajax({
           type: "POST",
           url: "userdata.php",
           data: {"iduser": iduser},
           dataType: 'json',
           cache: false,
           success: function(data1){
           userda += '<li data-role="list-divider">Name</li>';
           userda += '<li>'+data1.data.fname+' '+data1.data.lname+'</li>';
           userda += '<li data-role="list-divider">Money</li>';
           userda += '<li>'+data1.data.money+'</li>';
           userda += '<li data-role="list-divider">Headlines</li>';
           $.each(data1.headlines, function(i, currentObj) {
                  userda += '<li>' + currentObj + '</li>​';
                  });
           $('ul#userdatalist').html(userda).listview('refresh');
           }
           });

我的 HTML 文件看起来像

<ul data-role="listview" data-inset="true" data-theme="c" data-divider-theme="a" id="userdatalist">
                    </ul>

并且(json)数据看起来像:

{"data":{"fname":"test","lname":"test","money":"47"},"headlines":["Promis","Unterhaltung","Unterwaesche"]}

结果如下:http://imageshack.us/photo/my-images/705/bildschirmfoto20120619uj.png/

我看不到任何问题,但我的第二个列表视图也有同样的问题。

【问题讨论】:

  • 你的 CSS 是什么样的?
  • 这是一个很好的观点。我有几个css文件,我会看看它们!但另一个问题:使用 jquery-mobile 需要 jquery.js 和 jquery-mobile.js 吗?因为当我删除其中一个时,我失去了我的应用程序中的所有主题。因为我想使用 zepto.js 进行加载...
  • 是的,jQM 工作都需要它们。你不能只是将 zepto 换成 jquery 并期望它能够工作,但是你可以模仿 DOM 并使用它们的 css 文件;)
  • 谢谢。所以现在我已经删除了我所有的 .css 文件,只包含了 jquery-mobile.css 和 jquery-mobile.js 和 jquery.js,但是问题没有解决......和往常一样......跨度>
  • 如果您删除了 css 文件,那么它的 defos 不应该仍然是那样的。您可以尝试清除浏览器缓存,或者在 chrome 开发者控制台的设备中禁用浏览器缓存吗?

标签: php jquery json listview jquery-mobile


【解决方案1】:

两个想法:

  1. 您是否有任何 .live() 或 .delegate() 函数可能会弄乱您的列表?

  2. 您可以尝试使用标准 for 循环并与 jquery 结合(因为您在“成功”中使用标准 js 而不是 jquery)或因此在您的 .each()-loop 中使用 jquery:

    var $ul = $('ul#userdatalist'); // selector to the ul being filled 
                                    // (btw: since an id has to be unique, 
                                    // it is useless to prepend the tagType
    
    $ul.append(userda); // this is the jquery way -
                        // more or less ;)
    
    for (var i = 0;i < data1.headlines.length; i++) {
        $e = $("<li/>").text(data1.headlines[i]); // you could do this in your 
                                                  //.each()-loop as well, thus 
        $u.append($e);                            // sticking to jquery            
    }
    

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多