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