Knockout binding not working with drag/resize
Thanks @troolee for this wonderful work,
I worked on Knockout example provided with demo. The array of widgets is observableArray. The properties of widgets like x, y, width, height etc are also made observable. So that I can change it manually at run time.
It works till the extent that I can change dimensions and positions from text inputs but "How we can change widgets properties with drag/resize so that it gets reflected in viewmodel also".
Basically, I want to save changed properties (using drag/resize) to a server.
Please look at code at https://github.com/getrupendra/gridstack
Thanks in Advance.
The issue is with knockout itself. Attribute binding is not twoway. I worked arround the issue like this: Ps this code is part of a larger 'dashboard' custom binding.
$dashboard.on('change', function (event, items) {
_.forEach(items, function (i) {
var data = ko.dataFor(i.el[0]);
if (data.XPosition() !== i.x) {
data.XPosition(i.x);
}
if (data.YPosition() !== i.y) {
data.YPosition(i.y);
}
if (data.Width() !== i.width) {
data.Width(i.width);
}
if (data.Height() !== i.height) {
data.Height(i.height);
}
});
});
I will surely give it a try. Thanks Friso :)
@getrupendra Did you have success? I'm closing this ticket, but feel free to reopen if you still have concerns.
The answer posted worked for me.
I'm curious, is this a problem that a custom binding would be able to fix? I'm confused as to why Knockout wouldn't list this as a limitation on their website.