Design and Development of Windows 8 Metro-listviews and data binding (2)

Source: Internet
Author: User
Load recipe data

The project already contains sample data, but you want to replace it with your own data. In practice
2. If you connectInternetYou can retrieve data from the cloud. If you are not connectedInternetOr you want the application to use local data instead of remote data.

Task1-Prepare Local recipe data

If you are not connectedInternetOr you want the application to use local data instead of cloud data, perform the following steps. If you wantAzureObtain recipe data. You canSkip task1 Execute the task directly
2.

1.

1.InContosocookbook
Create a project namedData.

2.
Place the original lab materialDataFolder namedRecipes.txtFile to the ProjectDataFolder.

Note:If you take the time to viewRecipes.txt
Content in, you will see that it only containsJSONEncoding data. Besides ImageURL.
AzureThe retrieved data is the same.

3. the name is " Chinese ", " French ", " German ", " Indian ", " Italian ", and " images folder to the images folder of the project. It is important to put them in the images folder because images in recipes.txt
URL are located here.
to copy these files, you only need to copy them from Windows
drag the resource manager to Solution Explorer .

 

Task2-Load recipe data

The next step isData. js
Sample Data in (Visual StudioIn
JSFolder to load recipe data.Code.Even if you have executed the task
1
,You still need to execute this task.

 

1.OpenData. jsAnd delete (or comment out)"Use strict"And
GroupkeyselectorAll rows between functions.

Note:The row you just deleted is used to declare and initialize it with the name
SamplegroupsAndSampleitemsArray containing sample data. Because you replace the sample data with actual data, you no longer need these arrays.

2.In this file, delete or comment out the following statements:


Javascript

Sampleitems. foreach (function (item)
{

List. Push (item );

});

3.InForeach
Add the following statement to the loop:


Javascript

Winjs. xhr ({URL: "http://contosorecipes8.blob.core.windows.net/AzureRecipes "})

. Then (function (xhr)
{

VaR items = JSON. parse (xhr. responsetext );

 

//
Add the items to the winjs. Binding. List

Items. foreach (Function
(Item ){

List. Push (item );

});

});

Note:Use the code just added
Windows library for JavascriptOfWinjs. xhr
Function will be asynchronousXMLHttpRequestSubmit
Azure. Use the returned recipe dataJSONEncoding and passed toXhrObjectResponsetext
Read attributes. Even if you do not useXMLHttpRequestAnd do not worryMetroCross-source restrictions in. The call is successful even if the target is in a different domain!

4.If you use local data (that is, you have executed the task1).Urlpassed to winjs. xhrReplace with"../Data/recipes.txtTo reference local data files.

5.PressF5Debug an applicationProgramCheck whether the start page is shown in.




Figure8

Start page containing recipe

6.ReturnVisual StudioAnd stop debugging.

Note: ThisArticleThis is the script for Windows 8 online lab on msdn. It is for your reference only. If you want to experience the complete experiment, click the msdn online lab below

Http://msdn.microsoft.com/zh-cn/hh968278

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.