Created
December 1, 2012 16:59
-
-
Save kamranayub/4183235 to your computer and use it in GitHub Desktop.
Knockout View Binding Support for WinJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Via Kamranicus: http://kamranicus.com/Blog/Posts/59/using-knockout-bindings-in-your-winjs-application | |
// | |
// Include this before the rest of your app code (before default.js) | |
// | |
// <!-- WinJS references --> | |
// ... | |
// | |
// <script src="/scripts/knockout-2.2.js"> | |
// <script src="/scripts/ko-winjs.js"> | |
// | |
// <!-- Rest of your code --> | |
// ... | |
// | |
// ********************************* | |
// WARNING: This is still an experimental idea. This possibly will be inefficient. Use at your own risk! | |
// ********************************* | |
(function() { | |
"use strict"; | |
// | |
// Knockout View Binding support | |
// | |
var superProcessAll = WinJS.Binding.processAll; | |
WinJS.Binding.processAll = function (rootElement, dataContext, skipRoot, bindingCache) { | |
if (dataContext) { | |
ko.applyBindings(dataContext, rootElement); | |
} | |
return superProcessAll.call(this, rootElement, dataContext, skipRoot, bindingCache); | |
}; | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Now you can use both bindings! --> | |
<div id="item-tmpl" data-win-control="WinJS.Binding.Template"> | |
<div class="item" data-bind="css: { toggledClass: someBoolProp }"> | |
<h2 class="win-type-medium" data-bind="text: name"></h2> | |
<div class="item-logo" | |
data-win-bind="style.backgroundImage: logoUrl Converters.cssBackgroundify" | |
data-bind="visible: showLogo"> | |
</div> | |
</div> | |
</div> | |
<div id="my-list" | |
data-win-control="WinJS.UI.ListView" | |
data-win-options="{ itemTemplate: select('#item-tmpl') }"> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Source article: http://kamranicus.com/Blog/Posts/59/using-knockout-bindings-in-your-winjs-application