开发者

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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜