gpt4 book ai didi

ember.js - 如何在 ember 中使用鼠标拖动来选择元素?

转载 作者:行者123 更新时间:2023-12-01 06:24:35 26 4
gpt4 key购买 nike

SCREEN SHOT我有这样的模板,

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

在我的 js 中,我使用一个 View 来选择一个被点击的元素,例如,

型号:

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

选择 View :

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。当我使用鼠标拖动时,我需要选择它们。

如何使用鼠标拖动选择来做到这一点?请帮我解决这个问题。

演示:JSBIN

最佳答案

draggable 属性添加到您的 View 并使用 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.

关于ember.js - 如何在 ember 中使用鼠标拖动来选择元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30126450/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com