data.js
現在、Grid アプリ テンプレートによって提供されるデータを非同期的に読み込んでいます。StorageFile クラスの非同期の性質により、グローバルな WinJS 名前空間が設定される前にgroupedItems.js
(「ハブ」ページ) がハンドラーで呼び出さ_initializeLayout
れる場所に問題が存在します。ready
Data
でdata.js
:
fileNames.forEach(function (val, index, arr) {
var uri = new Windows.Foundation.Uri('ms-appx:///data/' + val + '.geojson');
Windows.Storage.StorageFile.getFileFromApplicationUriAsync(uri).then(function (file) {
Windows.Storage.FileIO.readTextAsync(file).then(function (contents) {
// ... read, parse, and organize the data ...
// Put the data into the global namespace
WinJS.Namespace.define("Data", {
items: groupedItems,
groups: groupedItems.groups,
getItemReference: getItemReference,
getItemsFromGroup: getItemsFromGroup,
resolveGroupReference: resolveGroupReference,
resolveItemReference: resolveItemReference
});
});
});
}
でgroupedItems.js
:
// ...
// This function updates the ListView with new layouts
_initializeLayout: function (listView, viewState) {
/// <param name="listView" value="WinJS.UI.ListView.prototype" />
if (viewState === appViewState.snapped) {
listView.itemDataSource = Data.groups.dataSource;
listView.groupDataSource = null;
listView.layout = new ui.ListLayout();
} else {
listView.itemDataSource = Data.items.dataSource;
listView.groupDataSource = Data.groups.dataSource;
listView.layout = new ui.GridLayout({ groupHeaderPosition: "top" });
}
},
// ....
このコードをこのファイルからdone()
Promise の関数に移動できないので、レイアウトを初期化する前に WinJS 名前空間で が初期化されるdata.js
までアプリケーションを待機させるにはどうすればよいですか?Data