我在主干中有一个应用程序,其中带有一些按钮,我可以添加动态可拖动和可调整大小的元素。这些元素被添加到模型集合中,当我停止例如拖动时,我设置了元素的新坐标,但是设置了LAST元素不是我拖动的元素。我该如何解决?这是我的应用视图
define(['jquery' ,
'backbone',
'jquery_ui',
'models/design',
'collections/design',
'views/element',
"text!templates/design.html"
],
function($, Backbone, jQueryUI, DesignModel, DesignCollection, ElementView, tmplDesign){
var DesignView = Backbone.View.extend({
initialize: function(){
this.$el = $('#layout');
this.template = tmplDesign;
this.elementModel = null;
this.collection = new DesignCollection();
var here = this;
$('#insert-dynamic-element').click(function(){
var element = { designId:here.collection.models.length , name:'img', type:'image', width:'100px', height:'50px', top:'0', left:'0'};
here.elementModel = new DesignModel(element);
here.collection.addElement(here.elementModel);
here.render();
$(function() {
$('.drag-item').draggable({
snap : true,
cursor : "move",
delay : 100,
scroll : false,
containment : "parent",
stop: function (e, ui){
here.elementModel.set({ left:$(this).css('left'), top: $(this).css('top')});
here.collection.set(here.elementModel, {remove:false});
//--------------- HERE I WANT TO SET THE RIGHT ELEMENT DRAGGED NOT THE LAST!!! ------------------------------
}
});
});
});
},
render: function(){
var template = _.template(this.template, {elements:this.collection.toJSON()});
this.$el.empty();
this.$el.html(template);
}
})
return DesignView;
});