日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢(xún)
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
操作實(shí)例:創(chuàng)建博客閱讀器(JavaScript 和 HTML)

此操作實(shí)例指導(dǎo)你如何使用拆分應(yīng)用 Visual Studio 模板來(lái)創(chuàng)建博客閱讀應(yīng)用。

Important  此操作實(shí)例適用于 Microsoft Visual Studio 2012 和 Windows 8。 部分內(nèi)容在 Microsoft Visual Studio 2013 Preview 和 Windows 8.1 Preview 中可能無(wú)法正常運(yùn)行。

了解操作方法:

  • 定義自己的 JSON 數(shù)據(jù)
  • 使用 Windows.JS.xhr 檢索 RSS 數(shù)據(jù)
  • 使用 PageControl 對(duì)象
  • ListView 中顯示數(shù)據(jù)
  • 使用 AppBar 響應(yīng)命令

WindowsBlogReader

在本教程中,我們?yōu)槟承?Windows 團(tuán)隊(duì)博客創(chuàng)建了一個(gè)基本的閱讀器。完成后的應(yīng)用外觀如下所示:

該項(xiàng)頁(yè)面題為 "Windows 團(tuán)隊(duì)博客",并包含一個(gè) ListView 控件(每個(gè)博客一項(xiàng))。當(dāng)在 ListView 中單擊某項(xiàng)時(shí),可以導(dǎo)航到所選博客的拆分頁(yè)。該拆分頁(yè)包含一個(gè) ListView 控件(每篇博客文章一項(xiàng)),同時(shí)還包含一個(gè)控件用于縱向顯示當(dāng)前所選的博客文章的內(nèi)容。從拆分頁(yè)可以導(dǎo)航到項(xiàng)目詳細(xì)信息頁(yè)面,在詳細(xì)信息頁(yè)面中,博客文章的標(biāo)題顯示在頂部,當(dāng)前所選博客文章的內(nèi)容以水平方式顯示。

在 Visual Studio 中創(chuàng)建新項(xiàng)目

為我們的應(yīng)用創(chuàng)建一個(gè)名為 WindowsBlogReader 的新項(xiàng)目。以下是操作方法:

  1. 啟動(dòng) Visual Studio。
  2. 在“起始頁(yè)”選項(xiàng)卡中,單擊“新建項(xiàng)目”。隨即將打開(kāi)“新建項(xiàng)目”對(duì)話框。
  3. 在“已安裝”窗格中,展開(kāi) JavaScript 并選擇“Windows 應(yīng)用商店應(yīng)用”模板類(lèi)型。JavaScript 可用的項(xiàng)目模板隨即將顯示在對(duì)話框的中心窗格中。
  4. 在中心窗格中,選擇“拆分應(yīng)用”項(xiàng)目模板。
  5. 在“名稱(chēng)”文本框中,輸入 "WindowsBlogReader"。
  6. 單擊“確定”以創(chuàng)建項(xiàng)目。這需要花費(fèi)一點(diǎn)時(shí)間。

下面是在解決方案資源管理器中顯示的項(xiàng)目的結(jié)構(gòu)。頁(yè)面文件夾包含兩組文件,一組文件用于項(xiàng)頁(yè)面,另一組文件用于拆分頁(yè)面。這些組中的每個(gè)組為 PageControl、一組 HTML、CSS 以及 JavaScript 文件,這些文件定義應(yīng)用可以導(dǎo)航至或用作自定義控件的頁(yè)面。

新項(xiàng)目包含創(chuàng)建項(xiàng) PageControl 和拆分 PageControl 所需的 HTML、CSS 和 JavaScript 文件。稍后我們將為項(xiàng)詳細(xì)信息 PageControl 添加文件。

啟動(dòng)我們的新 Windows 應(yīng)用商店應(yīng)用

如果你非常想看到基本的分隔應(yīng)用的外觀,請(qǐng)按 F5 以生成、部署并啟動(dòng)應(yīng)用。應(yīng)用顯示為全屏頁(yè)面,標(biāo)題為 "WindowsBlogReader",包含一列示例項(xiàng)目,顯示為網(wǎng)格。每個(gè)項(xiàng)目表示一組數(shù)據(jù)。點(diǎn)擊或單擊列表中的項(xiàng)目以導(dǎo)航至拆分頁(yè)。拆分頁(yè)包含兩個(gè) 核心內(nèi)容區(qū)域。在左側(cè),你可以看到與所選組關(guān)聯(lián)的項(xiàng)目列表。在右側(cè),可以看到所選項(xiàng)目的內(nèi)容??梢酝ㄟ^(guò)點(diǎn)擊或單擊頁(yè)面上的“后退”按鈕來(lái)返回項(xiàng)目頁(yè)。

運(yùn)行應(yīng)用時(shí),應(yīng)用會(huì)提取 items.html 中的(或其中鏈接的)HTML、CSS 和 JavaScript,并將其注入到作為應(yīng)用起始頁(yè)的 default.html 頁(yè)面中。對(duì)于在應(yīng)用容器中運(yùn)行的代碼默認(rèn)可以執(zhí)行的操作有一些限制。例如,你的應(yīng)用不能訪問(wèn) Internet 或攝像頭,除非你聲明應(yīng)用需要此訪問(wèn)權(quán)限,且用戶(hù)在安裝應(yīng)用時(shí)授予了此訪問(wèn)權(quán)限。如需了解詳細(xì)信息,請(qǐng)打開(kāi) package.appxmanifest,并轉(zhuǎn)至“許可范圍”選項(xiàng)卡。

更改標(biāo)題和背景色

我們來(lái)執(zhí)行兩個(gè)簡(jiǎn)單的任務(wù)來(lái)自定義應(yīng)用。

若要更改應(yīng)用標(biāo)題,請(qǐng)打開(kāi) items.html,然后將 itemspage 中的 h1 元素文本替換為 "Windows 團(tuán)隊(duì)博客",如此處所示。

 
 
 
 
  1.  
  2.     Windows Team Blogs 
  3.  

若要設(shè)置應(yīng)用的背景色,請(qǐng)打開(kāi) default.css,并將此 background-color 屬性添加到 #contenthost 中。

 
 
 
 
  1. #contenthost { 
  2.     height: 100%; 
  3.     width: 100%;     
  4.     background-color: #0A2562; 

按 F5 來(lái)生成、部署并啟動(dòng)此應(yīng)用。請(qǐng)注意,項(xiàng)目頁(yè)的標(biāo)題已更改,項(xiàng)目頁(yè)和拆分頁(yè)的背景色為藍(lán)色。

Note項(xiàng)目中的 images 文件夾包含默認(rèn)的文件,系統(tǒng)將這些文件用于應(yīng)用啟動(dòng)時(shí)應(yīng)用的磁貼和初始屏幕。在本教程中,我們不更改這些內(nèi)容,但是你可以按照自己的喜好使用其他圖像。只 需將要使用的圖像文件添加到 images 文件夾中即可。打開(kāi) package.appxmanifest,將“應(yīng)用程序 UI”選項(xiàng)卡上“徽標(biāo)”、“小徽標(biāo)”和“初始屏幕”的內(nèi)容替換為你的圖像文件的路徑。

#p#

替換示例數(shù)據(jù)

項(xiàng)目模板包含運(yùn)行應(yīng)用時(shí)看到的示例數(shù)據(jù)。我們使用這些步驟為 Windows 團(tuán)隊(duì)博客將這些示例數(shù)據(jù)替換為來(lái)自 ATOM 源的數(shù)據(jù):

刪除示例數(shù)據(jù)

打開(kāi) data.js,其中包含應(yīng)用的示例數(shù)據(jù)。

我們不需要 generateSampleData 函數(shù),因此你可以將它刪除。

 
 
 
 
  1. // Returns an array of sample data that can be added to the application's 
  2. // data list.  
  3. function generateSampleData() { 
  4.     // Omitted code. 
  5.  
  6.          

我們不需要此代碼,所以你可以將其刪除:

 
 
 
 
  1. // TODO: Replace the data with your real data. 
  2. // You can add data from asynchronous sources whenever it becomes available. 
  3. generateSampleData().forEach(function (item) { 
  4.     list.push(item); 
  5. }); 

設(shè)置變量和函數(shù)

將此代碼添加到 data.js(文件開(kāi)頭的 var list = new WinJS.Binding.List(); 聲明前面)。此代碼可設(shè)置我們所需的變量以及填充它們的函數(shù)。在執(zhí)行本教程中的步驟時(shí),你可以利用其中包含的注釋來(lái)找到每一步放置代碼的位置。

 
 
 
 
  1. // Set up array variables 
  2.  
  3. var dataPromises = []; 
  4. var blogs; 
  5.  
  6. // Create a data binding for our ListView 
  7.  
  8. var blogPosts = new WinJS.Binding.List(); 
  9.  
  10. // Process the blog feeds 
  11.  
  12. function getFeeds() {  
  13.     // Create an object for each feed in the blogs array 
  14.     // Get the content for each feed in the blogs array 
  15.     // Return when all asynchronous operations are complete 
  16.  
  17. function acquireSyndication(url) { 
  18.     // Call xhr for the URL to get results asynchronously 
  19.  
  20. function getBlogPosts() { 
  21.     // Walk the results to retrieve the blog posts 
  22.  
  23. function getItemsFromXml(articleSyndication, bPosts, feed) { 
  24.     // Get the info for each blog post 

定義博客列表

為了使這個(gè)示例簡(jiǎn)單一點(diǎn),我們?cè)?blogs 數(shù)組中包含一列硬編碼的 URL。

將此代碼添加到 getFeeds 函數(shù)。此代碼將 JSON 數(shù)組添加到 blogs 數(shù)組。每個(gè) JSON 數(shù)組都包含多個(gè) JSON 對(duì)象,以存儲(chǔ)來(lái)自源的內(nèi)容。JSON 對(duì)象是名稱(chēng)/值對(duì)的未經(jīng)排序的容器。例如,博客標(biāo)題存儲(chǔ)在一個(gè) JSON 對(duì)象中,該對(duì)象名為 title,還有一個(gè)從 ATOM 源檢索的值。使用 JSON 對(duì)象使我們將來(lái)自源的內(nèi)容綁定到應(yīng)用的控件變得很簡(jiǎn)單。

 
 
 
 
  1. // Create an object for each feed in the blogs array 
  2. blogs = [ 
  3.     key: "blog1", 
  4.     url: 'http://blogs.windows.com/skydrive/b/skydrive/atom.aspx', 
  5.     title: 'tbd', updated: 'tbd', 
  6.     acquireSyndication: acquireSyndication, dataPromise: null 
  7. }, 
  8.     key: "blog2", 
  9.     url: 'http://blogs.windows.com/windows/b/windowsexperience/atom.aspx', 
  10.     title: 'tbd', updated: 'tbd', 
  11.     acquireSyndication: acquireSyndication, dataPromise: null 
  12. }, 
  13.     key: "blog3", 
  14.     url: 'http://blogs.windows.com/windows/b/extremewindows/atom.aspx', 
  15.     title: 'tbd', updated: 'tbd', 
  16.     acquireSyndication: acquireSyndication, dataPromise: null 
  17. }, 
  18.     key: "blog4", 
  19.     url: 'http://blogs.windows.com/windows/b/business/atom.aspx', 
  20.     title: 'tbd', updated: 'tbd', 
  21.     acquireSyndication: acquireSyndication, dataPromise: null 
  22. }, 
  23.     key: "blog5", 
  24.     url: 'http://blogs.windows.com/windows/b/bloggingwindows/atom.aspx', 
  25.     title: 'tbd', updated: 'tbd', 
  26.     acquireSyndication: acquireSyndication, dataPromise: null 
  27. }, 
  28.     key: "blog6", 
  29.     url: 'http://blogs.windows.com/windows/b/windowssecurity/atom.aspx', 
  30.     title: 'tbd', updated: 'tbd', 
  31.     acquireSyndication: acquireSyndication, dataPromise: null 
  32. }, 
  33.     key: "blog7", 
  34.     url: 'http://blogs.windows.com/windows/b/springboard/atom.aspx', 
  35.     title: 'tbd', updated: 'tbd', 
  36.     acquireSyndication: acquireSyndication, dataPromise: null 
  37. }, 
  38.     key: "blog8", 
  39.     url: 'http://blogs.windows.com/windows/b/windowshomeserver/atom.aspx', 
  40.     title: 'tbd', updated: 'tbd', 
  41.     acquireSyndication: acquireSyndication, dataPromise: null 
  42. }, 
  43.     key: "blog9", 
  44.     url: 'http://blogs.windows.com/windows_live/b/developer/atom.aspx', 
  45.     title: 'tbd', updated: 'tbd', 
  46.     acquireSyndication: acquireSyndication, dataPromise: null 
  47. }, 
  48.     key: "blog10", 
  49.     url: 'http://blogs.windows.com/ie/b/ie/atom.aspx', 
  50.     title: 'tbd', updated: 'tbd', 
  51.     acquireSyndication: acquireSyndication, dataPromise: null 
  52. }, 
  53.     key: "blog11", 
  54.     url: 'http://blogs.windows.com/windows_phone/b/wpdev/atom.aspx', 
  55.     title: 'tbd', updated: 'tbd', 
  56.     acquireSyndication: acquireSyndication, dataPromise: null 
  57. }, 
  58.     key: "blog12", 
  59.     url: 'http://blogs.windows.com/windows_phone/b/wmdev/atom.aspx', 
  60.     title: 'tbd', updated: 'tbd', 
  61.     acquireSyndication: acquireSyndication, dataPromise: null 
  62. }]; 

#p#

檢索源數(shù)據(jù)

對(duì)于此部分中的步驟,我們使用適用于 JavaScript 的 Windows 庫(kù)來(lái)管理聯(lián)合源。

將此代碼添加到 acquireSyndication 函數(shù)。我們調(diào)用 Windows.JS.xhr 函數(shù)以檢索源內(nèi)容。此調(diào)用為異步調(diào)用。幸運(yùn)的是,程序已經(jīng)為我們處理好了在進(jìn)行異步調(diào)用時(shí)可能會(huì)遇到的許多復(fù)雜問(wèn)題。xhr 返回時(shí),我們將收到結(jié)果的承諾,此承諾將返回到調(diào)用方。

 
 
 
 
  1. // Call xhr for the URL to get results asynchronously 
  2. return WinJS.xhr( 
  3.     { 
  4.         url: url, 
  5.         headers: { "If-Modified-Since": "Mon, 27 Mar 1972 00:00:00 GMT" } 
  6.                  
  7.     }); 

現(xiàn)在,我們將代碼添加到 getFeeds 函數(shù)以調(diào)用 blogs 數(shù)組中每個(gè)博客的 acquireSyndication 函數(shù),并添加返回到我們 promise 數(shù)組的 promise dataPromises。我們先調(diào)用 WinJS.Promise.join 函數(shù),等待所有承諾均已滿(mǎn)足后,再?gòu)?getFeeds 返回。這可以確保在顯示 ListView 控件之前,我們擁有全部所需的信息。

 
 
 
 
  1. // Get the content for each feed in the blogs array 
  2. blogs.forEach(function (feed) { 
  3.     feed.dataPromise = feed.acquireSyndication(feed.url); 
  4.     dataPromises.push(feed.dataPromise); 
  5. }); 
  6.  
  7. // Return when all asynchronous operations are complete 
  8. return WinJS.Promise.join(dataPromises).then(function () { 
  9.     return blogs; 
  10. }); 

接下來(lái),將此代碼添加到 getBlogPosts 函數(shù)。對(duì)于 blogs 數(shù)組中的每個(gè)博客,我們針對(duì)所需的信息分析 XML 源數(shù)據(jù)。首先,我們使用 responseXML 屬性以獲得響應(yīng)正文,然后使用 querySelector 方法以及所需的選擇器來(lái)獲得博客的標(biāo)題和最后更新日期。我們使用 Windows.Globalization.DateTimeFormatting.DateTimeFormatter 來(lái)轉(zhuǎn)換顯示的上次更新日期。

如果 articlesResponse.responseXMLnull,則說(shuō)明加載博客時(shí)出錯(cuò),因此我們會(huì)在博客發(fā)布位置顯示一條錯(cuò)誤消息。

 
 
 
 
  1. // Walk the results to retrieve the blog posts 
  2. getFeeds().then(function () { 
  3.     // Process each blog 
  4.     blogs.forEach(function (feed) { 
  5.         feed.dataPromise.then(function (articlesResponse) { 
  6.  
  7.             var articleSyndication = articlesResponse.responseXML; 
  8.  
  9.             if (articleSyndication) { 
  10.                 // Get the blog title  
  11.                 feed.title = articleSyndication.querySelector("feed > title").textContent; 
  12.  
  13.                 // Use the date of the latest post as the last updated date 
  14.                 var published = articleSyndication.querySelector("feed > entry > published").textContent; 
  15.  
  16.                 // Convert the date for display 
  17.                 var date = new Date(published); 
  18.                 var dateFmt = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter( 
  19.                     "month.abbreviated day year.full"); 
  20.                 var blogDate = dateFmt.format(date); 
  21.                 feed.updated = "Last updated " + blogDate; 
  22.  
  23.                 // Get the blog posts 
  24.                 getItemsFromXml(articleSyndication, blogPosts, feed); 
  25.             } 
  26.             else { 
  27.                          
  28.                 // There was an error loading the blog.  
  29.                 feed.title = "Error loading blog"; 
  30.                 feed.updated = "Error";  
  31.                 blogPosts.push({ 
  32.                     group: feed, 
  33.                     key: "Error loading blog", 
  34.                     title: feed.url, 
  35.                     author: "Unknown", 
  36.                     month: "?", 
  37.                     day: "?", 
  38.                     year: "?", 
  39.                     content: "Unable to load the blog at " + feed.url 
  40.                 }); 
  41.  
  42.             } 
  43.         }); 
  44.     }); 
  45. }); 
  46.  
  47. return blogPosts; 

最后,將此代碼添加到 getItemsFromXml 函數(shù)。首先,我們使用 querySelectorAll 來(lái)獲得博客文章集以及每篇博客文章的信息。然后,我們使用 querySelector 來(lái)獲得每篇博客文章的信息。我們使用 Windows.Globalization.DateTimeFormatting.DateTimeFormatter 來(lái)轉(zhuǎn)換顯示的上次更新日期。最后,我們使用 push 方法將每篇博客文章的信息存儲(chǔ)在 bPosts 數(shù)組中的相應(yīng)條目中。

 
 
 
 
  1. // Get the info for each blog post 
  2. var posts = articleSyndication.querySelectorAll("entry"); 
  3.  
  4. // Process each blog post 
  5. for (var postIndex = 0; postIndex < posts.length; postIndex++) { 
  6.     var post = posts[postIndex]; 
  7.  
  8.     // Get the title, author, and date published 
  9.     var postTitle = post.querySelector("title").textContent; 
  10.     var postAuthor = post.querySelector("author > name").textContent; 
  11.     var postPublished = post.querySelector("published").textContent; 
  12.  
  13.     // Convert the date for display 
  14.     var postDate = new Date(postPublished); 
  15.     var monthFmt = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter( 
  16.         "month.abbreviated"); 
  17.     var dayFmt = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter( 
  18.         "day"); 
  19.     var yearFmt = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter( 
  20.         "year.full"); 
  21.     var blogPostMonth = monthFmt.format(postDate); 
  22.     var blogPostDay = dayFmt.format(postDate); 
  23.     var blogPostYear = yearFmt.format(postDate); 
  24.  
  25.     // Process the content so it displays nicely 
  26.     var staticContent = toStaticHTML(post.querySelector("content").textContent); 
  27.  
  28.     // Store the post info we care about in the array 
  29.     bPosts.push({ 
  30.         group: feed, 
  31.         key: feed.title, 
  32.         title: postTitle, 
  33.         author: postAuthor, 
  34.         month: blogPostMonth.toUpperCase(), 
  35.         day: blogPostDay, 
  36.         year: blogPostYear, 
  37.         content: staticContent 
  38.     });                                          

#p#

使數(shù)據(jù)可用

現(xiàn)在,我們已完成了將源數(shù)據(jù)存儲(chǔ)到數(shù)組中的代碼,我們需要按照 ListView 控件的預(yù)期來(lái)對(duì)源數(shù)據(jù)進(jìn)行分組。我們還需要完成將源數(shù)據(jù)綁定到 ListView 控件這一任務(wù)。

getItemsFromGroup 函數(shù)調(diào)用 createFiltered 方法,并返回指定博客的博客文章。getItemsFromGroup 函數(shù)依賴(lài)變量 list。

 
 
 
 
  1. var list = new WinJS.Binding.List(); 

將此定義替換為對(duì) getBlogPosts 函數(shù)的調(diào)用,該函數(shù)返回 blogPosts 變量。這是一個(gè) WinJS.Binding.List 對(duì)象。

 
 
 
 
  1. var list = getBlogPosts(); 

注意,調(diào)用 createGrouped 方法將按指定的鍵(此情況中是指每篇文章所屬的博客)對(duì)博客文章排序。

 
 
 
 
  1. var groupedItems = list.createGrouped( 
  2.     function groupKeySelector(item) { return item.group.key; }; 
  3.     function groupDataSelector(item) { return item.group; } 

更新項(xiàng) PageControl

項(xiàng) PageControl 的主要功能是使用 WinJS.UI.ListView 實(shí)現(xiàn)的 ListView 控件。每個(gè)博客在此列表中都有一個(gè)項(xiàng)目。讓我們修改模板中提供的 ListView 項(xiàng),以包含博客標(biāo)題和上次更新博客的日期。

打開(kāi) items.html。我們需要更新此 div 標(biāo)記中的 HTML,從而在我們的 blogs 數(shù)組中反映內(nèi)容。

 
 
 
 
  1.  
  2.      
  3.          
  4.          
  5.              
  6.              
  7.         
 
  •     
  •  
  •  

    進(jìn)行以下更新:

    1. 因?yàn)椴皇敲總€(gè)博客都有圖像,因此請(qǐng)刪除 img 標(biāo)記。
    2. h6 標(biāo)記中,將 textContent: subtitle 更新為 textContent: updated。這會(huì)在 ListView 項(xiàng)目的覆蓋部分中放置上次更新日期。
    3. 移動(dòng)位于類(lèi) item-overlaydiv 之前的 h4 標(biāo)記。這會(huì)在 ListView 項(xiàng)目的主要部分中放置博客標(biāo)題。

    結(jié)果如下所示。

     
     
     
     
    1.  
    2.      
    3.          
    4.                     
    5.              
    6.         
     
  •     
  •  
  •  

    若要將列表項(xiàng)目的顏色設(shè)置為淺藍(lán)色,請(qǐng)打開(kāi) items.css 并添加此處所示的 background-color 屬性。此外,在 -ms-grid-rows 屬性中將第二行的大小從 90px 更改為 60px,如此處所示,因?yàn)槲覀冎伙@示覆蓋中的上次更新日期。

     
     
     
     
    1. .itemspage .itemslist .item { 
    2.     -ms-grid-columns: 1fr; 
    3.     -ms-grid-rows: 1fr 60px; 
    4.     display: -ms-grid; 
    5.     height: 250px; 
    6.     width: 250px; 
    7.     background-color: #557EB9; 

    若要為博客標(biāo)題設(shè)置字體大小和邊距,請(qǐng)將此代碼添加到 items.css。

     
     
     
     
    1. .itemspage .itemslist .win-item .item-title { 
    2.     -ms-grid-row: 1; 
    3.     overflow: hidden; 
    4.     width: 220px; 
    5.     font-size:  24px; 
    6.     margin-top: 12px; 
    7.     margin-left: 15px; 

    更新拆分 PageControl

    打開(kāi) split.html。模板中拆分頁(yè)的 HTML 使用與示例數(shù)據(jù)相同的名稱(chēng)。我們需要更新此 div 標(biāo)記中的 HTML,從而在我們的 blogPosts 數(shù)組中反映名稱(chēng)。

     
     
     
     
    1.  
    2.      
    3.          
    4.          
    5.              
    6.              
    7.              
    8.         
     
  •     
  •  
  •  

    進(jìn)行以下更新:

    1. 將 img 標(biāo)記替換為新的
      ...
      節(jié)點(diǎn)。
    2. 在 h6 標(biāo)記中,將 textContent: subtitle 改為 textContent: author。
    3. 刪除 h4 標(biāo)記

    結(jié)果如下所示。

     
     
     
     
    1.  
    2.      
    3.         
    4.           

       
    5.            |  
    6.            
    7.        
     
  •          
  •              
  •              
  •         
  •  
  •     
  •  
  •  
  • 注意,我們將管道字符用作分隔符,因?yàn)?HTML 不包含用于繪制豎線的標(biāo)記。

    因?yàn)槲覀儧](méi)有包含在示例數(shù)據(jù)中的所有信息,所以從 articleSection 刪除此代碼可以簡(jiǎn)化頁(yè)面。

     
     
     
     
    1.  
    2.      
    3.          
    4.          
    5.      
    6.      
    7.  

    #p#

    若要設(shè)置文本塊的顏色以及文本的項(xiàng)目日期、字體和邊距,請(qǐng)打開(kāi) split.css 并添加此代碼。

     
     
     
     
    1. .splitpage .itemlistsection .itemlist .item .item-date { 
    2.     -ms-grid-column:  1; 
    3.     background-color: #557EB9; 
    4.  
    5.     .splitpage .itemlistsection .itemlist .item .item-date .item-month{ 
    6.         margin-top: 12px; 
    7.         margin-left: 12px; 
    8.         margin-bottom: 4px; 
    9.         font-weight: bold; 
    10.         font-size: 28px; 
    11.     } 
    12.  
    13.     .splitpage .itemlistsection .itemlist .item .item-date .item-day{ 
    14.         margin-left: 12px; 
    15.         font-size: 28px; 
    16.     } 

    若要獲取我們所需的頁(yè)面布局,請(qǐng)將此 -ms-grid-row 屬性從 "1" 改為 "2"。這導(dǎo)致頁(yè)面標(biāo)題填滿(mǎn)整個(gè)第一行,并且將 ListView 和文章放在第二行。

     
     
     
     
    1. .splitpage .articlesection { 
    2.     -ms-grid-column: 2; 
    3.     -ms-grid-row: 2; 
    4.     -ms-grid-row-span: 2; 
    5.     margin-left: 50px; 
    6.     overflow-y: auto; 
    7.     padding-right: 120px; 
    8.     position: relative; 
    9.     z-index: 0; 

    現(xiàn)在,來(lái)試試再次運(yùn)行應(yīng)用吧。按 F5 可構(gòu)建、部署并啟動(dòng)此應(yīng)用??梢粤⒓纯吹巾?yè)面標(biāo)題,但是應(yīng)用檢索源數(shù)據(jù)時(shí)有短暫的延遲。滿(mǎn)足所有承諾后,可以看到在 ListView 中每個(gè)博客一個(gè)項(xiàng)。(此代碼以滿(mǎn)足承諾的順序?qū)⑦@些項(xiàng)添加到 ListView 中。)點(diǎn)擊或單擊 ListView 中的項(xiàng)會(huì)將你帶到拆分頁(yè),此拆分頁(yè)包含所選博客的博客文章列表以及所選博客文章的內(nèi)容。默認(rèn)選中第一篇博客文章。

    單擊“后退”箭頭可返回到項(xiàng)頁(yè)。請(qǐng)注意,返回到屏幕的磁貼帶有過(guò)渡動(dòng)畫(huà)。這是 Windows JavaScript 庫(kù)中的一個(gè)功能,它支持控件以及其他用戶(hù)界面元素按照 Windows 應(yīng)用商店應(yīng)用的 UX 指南移動(dòng)。

    添加項(xiàng)詳細(xì)信息 PageControl

    項(xiàng)詳細(xì)信息 PageControl 將博客文章的標(biāo)題顯示為自己的標(biāo)題,并有一塊區(qū)域包含博客文章的內(nèi)容。

    添加項(xiàng)詳細(xì)信息 PageControl 的步驟:

    1. 在解決方案資源管理器中,右鍵單擊 pages 文件夾,選擇“添加”>“新建文件夾”。
    2. 將該文件夾命名為 itemDetail。
    3. 在解決方案資源管理器中,右鍵單擊 itemDetail 文件夾,選擇“添加”>“新建項(xiàng)”。
    4. 選擇“JavaScript”>“Windows 應(yīng)用商店”>“頁(yè)面控件”,然后使用文件名 itemDetail.html。
    5. 單擊“添加”以在 pages/itemDetail 文件夾中創(chuàng)建 itemDetail.css、itemDetail.html 和 itemDetail.js 文件。

    打開(kāi) itemDetail.html 并更新此處所示的主要部分。此代碼定義頁(yè)面布局。(這是網(wǎng)格應(yīng)用模板中包含的 itemDetail.html 頁(yè)面代碼的簡(jiǎn)化版本。)

     
     
     
     
    1.  
    2.  
    3.  
    4.      
    5.     itemDetail 
    6.  
    7.      
    8.      
    9.      
    10.      
    11.  
    12.      
    13.      
    14.  
    15.  
    16.      
    17.          
    18.              
    19.              
    20.                 < 新聞名稱(chēng):操作實(shí)例:創(chuàng)建博客閱讀器(JavaScript 和 HTML)
      當(dāng)前URL:http://www.dlmjj.cn/article/dhsoeig.html