BrandonLive

Binding helpers for WinJS

· updated July 10, 2013 · Technology, WinJS

While writing my first JS app for the Windows Store, I found several features of WinJS to be very useful. One feature I used in several places is its data binding and templating support. Along the way, I discovered that custom initializers could be used to great effect.

You can download the set of helpers I created by right-clicking here and choosing “Save As…” from the menu.

What’s included? Here’s a quick summary (replicated in the comments at the top of the file:

BindingHelpers.displayNoneIfNull

Marks the element as display:none if the value is null or undefined.

Example:

Name:

BindingHelpers.displayNoneIfNotNull

Inverse of displayNonIfNull

BindingHelpers.originalIfNull

Uses the original (markup) value if the bound value is null or undefined.

No user name available.

BindingHelpers.fillStringTemplate

Treat the default (markup) value as a template, where the placeholder {value} is replaced with the bound value.

Name: {value}

BindingHelpers.fillLinkTemplate

Same as fillStringTemplate, but url encodes the value.

<a href=”http://website.com/accountLookup?id={value}” data-win-bind=”href: account.id BindingHelpers.fillLinkTemplate”>Account

BindingHelpers.stripHtmlTags

Strips HTML tags from the value (by inserting the value into a DIV and then extracting the innerText value).

BindingHelpers.toStaticHtml

Pre-processes the value using toStaticHTML.

BindingHelpers.appendToClasses

Allows you to bind the value as a class name to the classes property.

If you have questions, founds bugs or opportunities for improvement, or any other feedback – please share in the comment section!

3 comments from the old site

financial resource

Your means of explaining all in this paragraph is genuinely nice, all can easily know
it, Thanks a lot.

Saykor

.fillStringTemplate is exactly what I search. Thank you

smoothie recipes raw food

Whenever you find yourself with a banana that’s getting
a little too ripe, peel it, and then slice it.
But rather than scold them into eating their fruits and vegetables, I find that being creative works much nicer.

Store any extra servings in fridge for later in the day.