这是个最简单的例子,里面所有的Jscex文件都打包成了一个,可以打开看头部注释。使用代码如下:
(function () {
var MessageDialog =
Windows.UI.Popups.MessageDialog;
var UICommand = Windows.UI.Popups.UICommand;
var FileOpenPicker =
Windows.Storage.Pickers.FileOpenPicker;
var PickerViewMode =
Windows.Storage.Pickers.PickerViewMode;
var PickerLocationId =
Windows.Storage.Pickers.PickerLocationId;
var FileAccessMode =
Windows.Storage.FileAccessMode;
WinJS.Namespace.define("MyApp", {
showPhoto:
eval(Jscex.compile("winrt-async", function () {
var dlg
= new MessageDialog("Do you want to open a file?");
dlg.commands.push(new UICommand("Yes", null, "Yes"));
dlg.commands.push(new UICommand("No", null, "No"));
var
result = $await(dlg.showAsync());
var picker = new FileOpenPicker();
picker.viewMode = PickerViewMode.thumbnail;
picker.suggestedStartLocation = PickerLocationId.picturesLibrary;
picker.fileTypeFilter.push(".jpg");
var file = $await(picker.pickSingleFileAsync());
if (file != null) {
document.getElementById("myImg").src = URL.createObjectURL(file);
}
}
}))
});
})();
不用Jscex的等价代码:
(function () {
var MessageDialog =
Windows.UI.Popups.MessageDialog;
var UICommand = Windows.UI.Popups.UICommand;
var FileOpenPicker =
Windows.Storage.Pickers.FileOpenPicker;
var PickerViewMode =
Windows.Storage.Pickers.PickerViewMode;
var PickerLocationId =
Windows.Storage.Pickers.PickerLocationId;
var FileAccessMode =
Windows.Storage.FileAccessMode;
WinJS.Namespace.define("MyApp", {
showPhoto: function () {
var dlg
= new MessageDialog("Do you want to open a file?");
dlg.commands.push(new UICommand("Yes", null, "Yes"));
dlg.commands.push(new UICommand("No", null, "No"));
dlg.showAsync().then(function (result) {
var picker = new FileOpenPicker();
picker.viewMode = PickerViewMode.thumbnail;
picker.suggestedStartLocation = PickerLocationId.picturesLibrary;
picker.fileTypeFilter.push(".jpg");
picker.pickSingleFileAsync().then(function (file) {
if (file != null) {
document.getElementById("myImg").src = URL.createObjectURL(file);
}
});
}
});
}
});
})();