jQuery and Windows 8 JavaScript Metro Style Apps

前端 未结 9 1378
小蘑菇
小蘑菇 2021-02-02 11:31

Can jQuery be used in Windows 8 Metro-style apps developed using the JavaScript API? I\'m looking at the samples, and there\'s a lot of standard DOM manipulation like doc

相关标签:
9条回答
  • 2021-02-02 11:35

    Don't use any windows libraries like WinJS. Why would you want to lock yourself and be dependent on proprietary code? Stick with the usual stuff, i.e. HTML, CSS, JS(JQuery or otherwise). It will only make your future support/dev far more predictable ...

    0 讨论(0)
  • 2021-02-02 11:38

    tl;dr : you can use jQuery 1.7+, but it's not (yet?) fully integrated when markup modification is involved.


    Quote from the Dev Center (msdn)

    Using jQuery

    You can use jQuery in your Windows Store app using JavaScript, but only versions 1.7 and later. We recommend always using the latest version.

    That means that it will work, but you will encounter some non-standard behaviors as listed in the HTML and DOM API changes list (msdn)

    There are exceptions mentioned when setting the innerHtml property (among others : Making HTML safer) if there is unsafe markup, but this is non-blocking and the simple fact of loading the jQuery library (1.8.2) will trigger a few.

    As mentioned before, you do need to use a local copy of the library (no CDN).

    0 讨论(0)
  • 2021-02-02 11:45

    As with all third party JavaScript libraries there are a couple of things you should keep in mind.

    • Always try to include the .js sourcefile in your project when possible. Calling out to a CDN or external hosted location will flag you for some security checks you wouldn't normally have to go through.
    • I have used a couple of jQuery versions in coding my own apps. Some of them broke so keep in mind there is still no guarantee. Other libraries, like SoundJS, I used older versions that I know do work.
    • If you are looking for some examples of third party libraries I have some posts on Knockout and Upshot here:
    • http://blogs.msdn.com/b/davedev/archive/2012/05/02/connecting-to-wcf-ria-services-in-a-windows-8-metro-style-app-using-upshot-js-and-kockout-js.aspx

    I have also written a free Windows Store Gaming Kit that uses third party libraries you can grab the free source for that here: http://win8gamekit.codeplex.com

    0 讨论(0)
  • 2021-02-02 11:46

    Yes, it works, as will any JavaScript library. I verified it on one of the tablets they gave out at the BUILD conference.

    However, do not expect to use a CDN to load in the script. You have to download it, add it to the project, and reference it locally.

    0 讨论(0)
  • 2021-02-02 11:47

    You can use any JS library. I suspect that methods like WinJS.xhr (aka '$.ajax') where written so that WinJS doesnt have a dependency on jQuery.

    0 讨论(0)
  • 2021-02-02 11:47

    Actually you can download it through Visual Studio. If you download NuGet Package Manager.
    TOOLS->Add Packages & Extensions

    Search the left online packages for NuGet Package Manager and install.

    Then when in a project that you want jQuery, right click on your references and add a NuGet package, and search jQuery. That's what I use.

    0 讨论(0)
提交回复
热议问题