我正在嘗試使用jQuery Mobile製作跨平臺移動應用程序。jQuery Mobile JSON解析
我有一個JSON字符串,顯示有關特定對象的信息(請在這裏查看:http://app.calvaryccm.com/mobile/web/teachings/json?callback=?),我希望它變成一個連接到單個項目視圖的列表視圖。問題是,listview並不像列表一樣顯示。它幾乎就像沒有CSS的HTML。看看這裏:http://mbeta.calvaryccm.com/#teachings
這是JavaScript解析JSON字符串:
<!-- Getting Teaching Data -->
<script type="text/javascript">
$(document).ready(function() {
$.getJSON("http://app.calvaryccm.com/mobile/web/teachings/json?callback=?",
function (data) {
//remove any characters from the query that might be unsafe to use as an ID for a page
//data.pageId = data.MessageNumber.replace(/[^\w]/, "");
//Feed the data to the template and add the new page to the body.
var res = $("#teachingTemplate").tmpl(data); //.appendTo(document.body);
$("#teachings").append(res);
//Grab a reference to that shiny new page
//var newpage = $("#" + data.pageId);
});
});
//Makes date readable
function GetDate(jsonDate) {
var value = new Date(parseInt(jsonDate.substr(6)));
return value.getMonth() + 1 + "/" + value.getDate() + "/" + value.getFullYear();
}
這應該是列表視圖:
<script id="teachingTemplate" type="text/x-jquery-tmpl">
<div id="${MessageNumber}">
<div data-role="header">
<a data-icon="arrow-l" href="#" data-rel="back">Back</a>
<h1>${Title}</h1>
</div>
<div data-role="content">
<div class="teachingsForm">
<ul data-role="listview">
<li><a href="singleTeachingView" class="tableImage">
<img src="" alt=""/>
<h3>${Title}</h3>
<p>${Speaker} - ${GetDate(MessageDate)} - ${MessageNumber} {{if Book != null}} - ${Book.BookName} ${ChapterVerse}{{/if}}</p>
</a>
</li>
</ul>
</div>
</div>
<div data-role="footer">
<h4>2011 Calvary Chapel Melbourne</h4>
</div>
我不明白爲什麼我的lis tview沒有顯示正確。如果你想在行動中看到它,請看這裏:http://mbeta.calvaryccm.com/#teachings。我需要幫助讓我的列表視圖正確顯示並直接顯示在正確的頁面上。
你能解釋一下你想要的樣子嗎,我不明白。還想知道爲什麼你在那裏有一個空的img標籤? – 2011-12-23 14:56:59
我有一個未來的空圖像標記。在開發的後期,JSON字符串將包含在每個教學的圖像中。我希望它看起來像這樣:http://jquerymobile.com/test/docs/lists/lists-nested.html#&ui-page=0-8但我不知道如何。 – 2011-12-23 14:59:16
好的,我想我已經開始明白這筆交易是什麼。我懷疑在您的JSON內容從服務器返回之後,有* *必須做的*告訴jQuery再次查看內容以便它發揮它的魔力。我會盡力弄清楚如何做到這一點。 – Pointy 2011-12-23 15:54:45