BT

Your opinion matters! Please fill in the InfoQ Survey!

Data Link – A Data-Binding for jQuery

| by Jonathan Allen Follow 194 Followers on Oct 08, 2010. Estimated reading time: 1 minute |

A note to our readers: As per your request we have developed a set of features that allow you to reduce the noise, while not losing sight of anything that is important. Get email and web notifications by choosing the topics you are interested in.

The second of the three jQuery libraries by Microsoft adds support for two-way data binding. While it serves the same purpose, the implementation is very different than what you would see in WPF or Silverlight.

Data Link relies on a single method, link, to tie together input elements on a form and the target object. Much like setting a DataContext in XAML, link is called on the form itself. By default, this creates a two-way binding between every named input element and the matching fields on the object. However, there are many options available.

Instead of binding every element, developers can pass in a dictionary in the form of “{fieldName: "elementName", …}”. This will restrict the data binding to only the indicated pairs. For any specific element, one can also specify “twoWay: false” to prevent changes to an object from being propagated back to the input element.

Value converters are exposed much like the twoWay property, with the names “convert” and “convertBack”. Unlike XAML, you have the option of either passing in a function or defining the converter inline as an anonymous function. If other fields need to be changed as a result of changes to the bound field, it can be done via the converter method.

The jQuery Data Link API requires jQuery 1.4.3, which has not been released yet. You can get both jQuery 1.4.3 and jQuery Data Link from github. jQuery Data Link is licensed under both the MIT and GPL Version 2 licenses.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT