JohnLouderback / GDB

Generic Data Binder (GDB) for jQuery is a framework agnostic and extremely easy to use 2 way data binder. GDB binds views and models in realtime with live two-way binding and no hefty framework necessary.
http://gdb.thewebdev.guru/
Apache License 2.0
87 stars 11 forks source link

Not seeing model value in dom #11

Closed nevf closed 10 years ago

nevf commented 10 years ago

@JohnLouderback With the following code:

$(function(){
    var model = { name: "Ms. Trunchbull" };
    gdb( { login: model },
         {
            debugLogging: true,
            modelChangeCallback: function( o_changed ){
                console.log( 'In GDB modelChangeCallback() o_changed: ', o_changed );
            }
         }
    );

    // model.name = 'Nifty Neville';
});
<input type="text" class="form-control" id="InputName" data-bindto="login.name" placeholder="User Name">

I'm not seeing: "Ms. Trunchbull" displayed in the input element. If I uncomment model.name = 'Nifty Neville'; then 'Nifty Neville' is displayed.

Further when I type in the input field I see the console.log output from: modelChangeCallback()

-Neville

JohnLouderback commented 10 years ago

Hi Neville, This is actually expected behavior. I did this because its usually left up to a template engine to display initial values. I was thinking about adding GDB.render() method which would explicitly put data into the corresponding elements. Perhaps I can even optionally allow GDB to initialize in this way. Would you like this? Also, it seems you deleted your other post. Were you able to fix that problem?

nevf commented 10 years ago

Hi John, Because your examples initialize model property values, I assumed these would be rendered. It does seem confusing that this isn't the case and means the model and dom have different values.

An option makes sense and I'd default it to true, as I can't see why you wouldn't want this behaviour, can you?

Yes the other issue resolved itself! I've just started writing a Browser Extension for my app Clibu and this seemed like a good opportunity to use GDB. Testing Browser Extensions seems a bit flakey at times and I put the deleted issue down to that.

JohnLouderback commented 10 years ago

Hi Neville, I agree and I will try to add this feature by the end of tomorrow. I will also add a GDB.render() as well in the case of dynamically added content since there's no effective way to check when the DOM is changed.

nevf commented 10 years ago

Hi John, Sounds good. I'm in no hurry.

JohnLouderback commented 10 years ago

I'm going to update this readme with the new features and then commit the changes shortly.

JohnLouderback commented 10 years ago

Updated.