0

サンプル グリッド JavaScript テンプレートを使用して win8 アプリケーションを構築しています。

また、data.js ファイルを使用してデータをロードしています。ただし、これは次を使用します。

var content = "test content";

var sampleItems = [
{group: sampleGroups[0], title: "Title", description: "DESC", content: content},

しかし、コンテンツのテキストが長くなってきたので、IMG や P などの html 構文も入れたいと思っています。

上記の content 変数にローカルの html ファイルをロードする最も簡単な方法は何ですか?

ありがとう!

4

1 に答える 1

1

アプリケーションのローカル ストレージにある HTML ファイルを読み取るには、WinJS.Application.local オブジェクトの readText メソッドを使用します。

var loc = WinJS.Application.local;
loc.readText("fileName", "failed").done( /* Your success and error handlers */ );

アプリ パッケージに保存されているファイルを読み取るには、次のように実行します。

var myText;

var url = new Windows.Foundation.Uri("ms-appx:///html/filename.html"); 
Windows.Storage.StorageFile.getFileFromApplicationUriAsync(url).then(function (file) { 
    Windows.Storage.FileIO.readTextAsync(file).then(function (text) { 
        myText=text;
    }); 
}); 
于 2012-10-03T19:47:57.947 に答える