0

我正在向我的网页添加一些带有 js 的 li,对于这个 li,我使用一些 jquery 移动样式表:为了加载 js,我使用以下代码:

$(document).bind('pageshow', function () {
    LoadLaadPalen.init();
}

然后将使用此代码:

var myData = [
    {"Identifier":1,"Naam":"NOT Given","Adres":"Kopenhagen 9","Postcode":"0000LL","Plaats":"NOT Given","Longitude":"0.00000","Latitude":"0.00000"},
    {"Identifier":2,"Naam":"NOT Given","Adres":"NOT Given 1","Postcode":"0000LL","Plaats":"Rotterdam","Longitude":"0.00000","Latitude":"0.00000"},
    {"Identifier":3,"Naam":"NOT Given","Adres":"NOT Given 6","Postcode":"0000LL","Plaats":"Rotterdam","Longitude":"0.00000","Latitude":"0.00000"},
    {"Identifier":4,"Naam":"NOT Given","Adres":"NOT Given 1","Postcode":"0000LL","Plaats":"Den Haag","Longitude":"0.00000","Latitude":"0.00000"},
    {"Identifier":5,"Naam":"NOT Given","Adres":"NOT Given 218","Postcode":"0000LL","Plaats":"Zoetermeer","Longitude":"0.00000","Latitude":"0.00000"}
];

$('.result').append("moi");

var items = [];
$.each(myData, function(index, element) {
    $('.greenfluxlist').append('<a href="#" rel="external"><li id="' + element.Identifier + '"><h3>' + element.Naam + '</h3><p>' + element.Adres +  '</p></li></a>');
});

这必须附加到本节:

<div data-role="content" data-theme="a">
    <div id="laadpalen">
        <p><strong>Op deze locaties zijn laadpunten aanwezig:</strong></p>
        <div class="result">
            <ul class="greenfluxlist" data-role="listview" data-inset="true"></ul>
        </div>
    </div>
</div>

但不幸的是,我看不到任何风格。我只看到带有文本和蓝色标准链接的项目符号。而且如果我要检查源代码,没有任何 html li 代码,但在网页上我看到它们...

4

2 回答 2

3

看看你的 <li> 定义。它应该以 <li> 开头:

<li><a href="bmw.html">BMW</a></li>

您的格式不正确:

<a href="#" rel="external"><li id="' + element.Identifier + '"><h3>' + element.Naam + '</h3><p>' + element.Adres +  '</p></li></a>

尝试按照我向您展示的那样去做:

<li><a class=contact href="#" id="' + data.response[key].id + '" ><h1>' + data.response[key].label + '</h1><p>'+ data.response[key].customer + '</p></a></li>

以 <li> 开头,而不是 href :P 如果出现问题,请查看:jQuery docs。记得触发然后刷新列表:

$('.greenfluxlist').trigger('create');
$('.greenfluxlist').listview('refresh');
于 2012-09-14T10:39:53.330 回答
0

尝试添加如下内容:

$('.greenfluxlist').listview('refresh');

我可以给你举个例子。第一个附加函数:

function success(data)
            {
                var html ='';
                $.each(data.response, function(key, value) {
                html += '<li><a class=contact href="#" id="' + data.response[key].id + '" ><h1>' + data.response[key].label + '</h1><p>'+ data.response[key].customer + '</p></a></li>';
                $('#contact_listview').append($(html));
                html='';
                });
                $('#contact_listview').trigger('create');    
                $('#contact_listview').listview('refresh');
                $.hidePageLoadingMsg;
            }

现在是 html 定义:

<ul data-role="listview"  id="contact_listview" data-filter="true">

</ul>
于 2012-09-14T10:04:55.157 回答