2

How do we bind a JavaScript object's property to a jQuery option? We want to get notified when the JavaScript object's property changes - we are open to wrap this object into some other model that will trigger notifcation.

For example:

var someObj = {"Name": "Some Name"};
// Some code that will bind the above Name property to a jquery widget's option.

Then when Name changes in the above object, the jQuery widget's option should change.

We are already familiar with KO and "jQuery Data Link plugin". But, in both those, the destination should be a form element not a jQuery widget option.

Colin Brock
  • 21,267
  • 9
  • 46
  • 61
Amar
  • 1,906
  • 2
  • 16
  • 26
  • Coming from your [previous question](http://stackoverflow.com/questions/9066135/data-link-between-two-objects-in-jquery), I think I'm misunderstanding something...when I asked what you were trying to do, I think I just wanted more context, like _why_ do you want to achieve this? I can see the point of linking elements to change event handling, but if you update the variable you're, well, in control of, you'd surely be aware that it was changed? Either I'm missing something, or there is a design flaw I'm unaware of. Could you help me understand a bit better? :) – Chris Kempen Feb 07 '12 at 12:34
  • We are trying to setup some sort of databinding. So, if the bound data's property changes, we want to update our widget UI accordingly. So, we are tyring to listen to the data's property's changes. – Amar Feb 13 '12 at 13:57
  • Let's start here: what's changing the data property's value? Could you provide any other code samples that might illustrate your actual problem? – Chris Kempen Feb 13 '12 at 17:41
  • $.widget("my.stuInfo", { options: { Data :null, FirstName:null, LastName:null } _create :function(){ }}); take a look at the above code that is the sample of my widget. I will call that into my html like below. – Amar Feb 14 '12 at 14:27
  • In Html i will pass value for Data option, inside the "stuInfo" widget i need to bind Data's "firstName" to "FirstName" option in the widget, so that any changes to the "FirstName" option should reflect in the Data's "firstName". On other hand if i change the value of Data's "firstName" in html dynamically means it should affect the Widget's "FirstName" option. – Amar Feb 14 '12 at 14:28

0 Answers0