我在 requirejs 和主干中有一个应用程序,当我单击一个元素时,我会在页面中添加可拖动和可调整大小的 div 并将该元素插入集合中。如果我调整或拖动元素的大小,我想上传具有新值的元素数据,例如 div 或高度。有可能吗?
这是我的看法?
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;
console.log('initialize DesignView');
this.collection = new DesignCollection();
var here = this;
$('#insert-dynamic-element').click(function(){
//json to the collection with data t update
var element = { name:'img', type:'image', width:'100px', height:'50px' };
here.collection.addElement(element);
here.render();
$(function() {
$('.drag-item').draggable({
snap : true,
cursor : "move",
delay : 100,
scroll : false,
containment : "parent"
}).resizable({
containment : "parent",
stop: function(e, ui) {
var width = ui.size.width;
var height = ui.size.height;
//I want update this value of width and height into the collection
}
});
});
});
},
render: function(){
var template = _.template(this.template, {elements:this.collection.toJSON()});
this.$el.empty();
this.$el.append(template);
}
})
return DesignView;
});