2015-05-08 41 views
3

SCREEN SHOT我有我的模板就是這樣,如何使用鼠標在燼中拖動來選擇元素?

<div> 
    {{#each model as |item|}} 
     {{#view "selection" model=item}} 
      <div class="child_div">{{item.name}}</div> 
     {{/view}} 
    {{/each}} 
</div> 

在我的JS,我使用選擇點擊的元素像視圖,

型號:

App.IndexRoute = Ember.Route.extend({ 
    model: function() { 
     return [{'is_active':false, 'name':'One'}, {'is_active':false, 'name':'Two'}, {'is_active':false, 'name':'Three'}, {'is_active':false, 'name':'Four'},{'is_active':false, 'name':'Five'}]; 
    } 
}); 

選擇視圖:

App.SelectionView = Ember.View.extend({ 
    classNameBindings: ["isActive"], 
    isActive: Ember.computed.alias('model.is_active'), // No I18N 
    click: function(){ 
     var self = this; self.get("controller").setEach("is_active", false); // No I18N 
     self.toggleProperty("isActive"); // No I18N 
    } 
}); 

在這裏,我選擇該div在點擊事件中。當我使用鼠標拖動時,我需要選擇它們。

我該如何做到這一點使用鼠標拖動選擇?請幫我解決這個問題。

DEMO:JSBIN

回答

0

draggable屬性添加到您的視圖,並使用dragStart事件。

attributeBindings : [ 'draggable' ], 
draggable   : 'true', 
dragStart: function(event) { 
    var self = this; 
    self.get("controller").setEach("is_active", false); // No I18N 
    self.toggleProperty("isActive"); 
} 

Here is working demo.

Here is a good article from Lauren Tan on drag n drop in Ember.

+0

感謝您的快速回復。我附上了我確切需要的截圖。看看截圖,讓我知道更多的方式。 –

+0

哦,我明白你的問題是錯的。那麼最簡單的方法是將jQuery UI可選小部件封裝到一個組件中並使用它。或者您可能需要對該代碼進行反向工程才能實現它。 – blessenm

相關問題