How to select an element using mouse drag in ember?

SCREEN SHOT I have my template like this,

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

      

In my js I am using a view to select an element with a click, for example

Model:

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'}];
    } 
});

      

Choice:

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
    }
});

      

Here I am selecting the div on the click event. I need to select them when I use drag and drop.

How do I do this using the mouse drag selection? Please help me with this.

DEMO: JSBIN

+3


source to share


1 answer


Add an attribute draggable

to your view and use the event 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 a working demo.

Here's a good article by Lauren Tan on dragging n in Ember.

0


source







All Articles