BorisMoore/jsviews — Issue #17: Linking to descendant leaf objects
Author: govis
Created: 2011-11-23 16:35:45+00:00
State: open

Hi Boris,

I am glad to see that you are making good progress with the new library and hope it will make it past beta this time.

I am binding to descendant leaf objects and making use of converter functions like so:

TEST
var data = {
Level1: {
Level2: 'ABC'
}
}
$("#element").link(data);

When I bind it first time the converter function gets called as expected

However when I change the underlying value, the converter function is not called:
$.observable(data).setProperty('Level1', { Level2: 'XVZ' });

I was digging around and narrowed the problem to the following code (jquery.views.js function addLinksFromData line 513)

// If 'from' path points to a property of a descendant 'leaf object',
// link not only from leaf object, but also from intermediate objects
while ( innerPath.length > 1 ) {
innerOb = innerOb[ innerPath.shift() ];
if ( innerOb ) {
addLinkFromData( innerOb, link, innerPath.join( "." ), cnvt, attr );
}
}
// The last trigger of get bindings will be called on adding the link (to get/initialize the value)
addLinkFromData( fromOb, link, 'Level1'/*path*/, cnvt, attr, !l && get );

As you can see in the last call to addLinkFromData, the path is ‘Level1.Level2’ but if I change it to the name of the root propery, which is 'Level1' in my case - everything works fine.

Please let me know if you agree that in the last call to the addLinkFromData the name of the root property property should be used in case of descendant leaf objects as it will be then used in addLinkFromData:

$(*Level1*).bind("propertyChange", handler);

Thanks