简体   繁体   中英

Win8 App Html/Js getting the version number (equivalent of PackageVersion)

I have ac#\\XAML Win8 Modern app that I have been tasked with turning into HTML\\JS.

In c# I could use:

PackageVersion currentVersion = new PackageVersion();

Is there an equivalent in js (I would guess it would be under something in WinJS )

Generally speaking, if it's an API that comes out of the Windows.* namespace, then it's usually available in JavaScript as well (with the exception of Windows.UI.Xaml.* and a smattering of others that aren't needed because JS has intrinsic APIs, as with JSON).

In this case, PackageVersion comes from Windows.ApplcationModel. The trick in JS is that you have to use fully qualified identifiers because there's not a using statement (so often we assign a local variable to the namespace and reference off that to save typing). So in your case, you'd be doing something like

var currentVersion = Windows.ApplicationModel.Package.current.id.version.

Or you can assign a namespace variable if you'll use it a lot:

var am = Windows.ApplicationModel;
var currentVersion = am.Package.current.id.version;

For anything in WinRT, just go to the docs page, eg http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.package.current.aspx , and click on the JavaScript tab under Syntax to see the specifics. If you don't get a syntax representation for JS, then that particular API isn't projected into JS.

Also, understand that WinJS is primarily a set of helper APIs and controls. You'll typically be using both WinRT APIs and WinJS APIs (though technically the latter are optional). They aren't mutually exclusive except for the WinJS UI parts that take the place of the XAML APIs in WinRT.

If you're getting into the JavaScript option, my free ebook from MSPress, Programming Windows Store Apps, in HTML, CSS, and JavaScript should help ramp you up, especially on the WinJS side of things.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM