How to data-bind .resizable().draggable()?
I know you can do this:
$(".myClass").resizable().draggable();
but 开发者_运维百科how would you use data-bind=""
to do the same thing?
The simplest way would be to define custom binding handlers for the behaviors:
ko.bindingHandlers.resizable = {
init: function(element, valueAccessor) {
var options = valueAccessor();
$(element).resizable(options);
}
};
ko.bindingHandlers.draggable = {
init: function(element, valueAccessor) {
var options = valueAccessor();
$(element).draggable(options);
}
};
Then, bind to it like:
<div data-bind="resizable: { }, draggable: { }"></div>
This allows you to pass any options that you want to the resizable and draggable calls.
Sample: http://jsfiddle.net/rniemeyer/eCZH4/
精彩评论