我试图通过从 TMDb 下拉电影数据并构建每个数据<li>
并将其附加到已经存在的<ul>
元素来动态生成 jQuery 移动列表视图。麻烦的是,无论我做什么,我都无法正确获取它的格式。我从 TMDb 获取数据和所有内容都很好,但是当我在这里调用时列表视图本身并没有设置样式$("#ul").listview("refresh");
是我的一些代码(相关内容):
AJAX CALL THAT GRABS DATA AND BUILDS EACH <li>:
$.ajax({
type: "POST",
data: {
action: 'searchFilm',
film: film
},
dataType: "json",
url: "./php/functions.php",
success: function(json) {
console.log(json);
for(var i = 0; i < Object.size(json); i++){
var film = json[i.toString()];
$('#film-search-results').append("<li data-theme='j'><img src='" + film.poster_path + "' alt='Poster' /><a href=''><h3 class='ui-li-heading'>" + film.title + "</h3><p class='ui-li-desc'><strong>" + film.tagline + "</strong></p><p class='ui-li-desc'>" + film.overview + "</p></a></li>");
}
},
error: function(jqxhr, status, text){
console.log(jqxhr);
}
});
EXISTING CONTENT DIV THAT HOLDS THE <ul> ELEMENT:
<div id="content-add-title" data-role="content">
<ul id='film-search-results' data-role='listview'></ul>
</div><!-- end content-add-title -->
AND THE FUNCTION THAT CALLS THE AJAX METHOD:
$('#add-add-title-btn').click(function() {
if ($('#add-title-type-select').val() === "movie") {
$('#right-panel3').panel("close");
$('#film-search-results').html("");
searchFilms($('#add-title-name-field').val());
$('#add-title-page').trigger("create");
$('#film-search-results').listview("refresh");
}
});
真的不知道为什么它不会正确样式任何人有任何想法?