2013-09-29 108 views
0

我需要一种方法来从控制器调用jQuery-UI方法。该方法是可分类的更新方法。当视图准备就绪时,我尝试使其可分类,但如何调用更新方法?控制器和视图是这样的:从控制器调用jQuery的方法

App.theController = Ember.ArrayController.extend({ 
method:function(){ 
    //calling update method of sortable 
} 
}); 

App.theView = Ember.View.extend({ 
didInsertElement:function(){ 
    this.$().sortable({ 
    update:function(){ 

    } 
    }); 
    } 
}); 

现在我想method鉴于sortable调用更新方法。

+0

我从来没有使用排序插件,而不是更新的说法是一个通过获取插件调用的回调?你为什么要自己打电话? – mavilein

+0

我不知道如何调用它,我问另一个[问题](http://stackoverflow.com/questions/19076233/calling-a-method-of-view-in-emberjs)找到一种方式 – MBehtemam

+0

什么是触发更新? 您可能希望视图中的观察者将依赖于控制器上的该触发器。 类似于:update:function(){}。observes(“controller.list”) –

回答

0

将可排序插件的update方法绑定到控制器中的函数。所以,每当sortable()更新被调用时,控制器功能被称为:

App.theView = Ember.View.extend({ 
    didInsertElement: function() { 
    this.$().sortable(); 
    var callback = this.get('controller.updateSortable'); 
    this.$().on('sortupdate', callback); 
    } 
}); 

App.theController = Ember.ArrayController.extend({ 
    updateSortable: function() { 
    // call me when sortable() update is called 
    } 
}); 
相关问题