在前一小節中可以看到,使用者每次點擊提要時均將調用readFeed()方法。因此我們即可在該readFeed ()方法中非同步呼叫伺服器端Web Service中的GetRssContent()方法,並將當前提要的ID傳遞過去。當然,在非同步呼叫之前同樣應該為使用者顯示出更新提示面板:
function readFeed(id) {
// 顯示更新提示面板。
showProgressBar(true);
// 取得提要的內容。
RssService.GetRssContent(id, onRssContentGot);
}
調用GetRssContent()方法時提供的回調方法onRssContentGot()的代碼如下。其中先隱藏了更新提示面板,然後使用Web Service返回的ContentEntry[]資料構造出了提要的內容,並顯示到頁面右側的內容地區中:
function onRssContentGot(result) {
// 隱藏更新提示面板。
showProgressBar(false);
// 構造提要內容HTML字串。
var contentBuilder = new Sys.StringBuilder();
for (var index = 0; index < result.length; ++index) {
contentBuilder.append("<h3><a href="");
contentBuilder.append(result[index].Link); // Link
contentBuilder.append("" target="_blank" >");
contentBuilder.append(result[index].Title); // Title
contentBuilder.append("</a></h3><div>");
contentBuilder.append(result[index].Content); //Content
contentBuilder.append("</div><hr />");
}
// 設定到提要內容元素上。
var content = $get("content");
content.innerHTML = contentBuilder.toString();
}