放入可拖动元素拖放到其他容器而不是本身?
参考了 JQuery UI Droppable 示例:购物车后。我重写它进行测试。但遇到了一些问题。
假设:
产品容器将产品拖放到购物车容器中。
<div class="products">
<ul>
<li> product 1 </li>
...
</ul>
</div>
和购物车容器:
<div class="shoppingCart1">
... dropped products here
</div>
和其他购物车容器:
<div class="shoppingCar2">
... dropped products here
</div>
我希望shoppingCart1的产品可以拖放到其他购物车< /strong> 容器而不是容器本身,反之亦然。例如:
问题是:
当产品已放入 s*hoppingCart1* 中时,然后我可以拖动并将 shoppingCart1 中的产品拖放到其他购物车容器中。但是,当我将产品拖放到自己的产品中时,它似乎还会附加 > 产品。我的意思是,当我拖动 shoppingCart1 的产品 并放入 shoppingCart1 本身时,它也会附加到 shoppingCart1 中。
非常感谢!
我的部分代码是从 JQuery UI Droppable 重写的:购物车 exmaple![ 不能按我想要的方式工作]
this.igtoMDMovieList = $('<div />',{'class':'igtoMDMovieList'})
.appendTo(this.igtoMDMovieListWrapper);
this.igtoMDMovieListOL = $('<ol />',{'class':'igtoMDMovieListOL'})
.html('<li class="placeholder">Add your items here</li>')
.appendTo(this.igtoMDMovieList)
.droppable({
accept:'li',
drop: function( event, ui ) {
$( "<li></li>" )
.text( ui.draggable.text() )
.appendTo(obj.igtoMDMovieListOL)//$(this).children()
.draggable({
appendTo: "#desktopFrame",
helper: "clone"
})
}
})
.sortable({
items: "li:not(.placeholder)",
sort: function() {
// gets added unintentionally by droppable interacting with sortable
// using connectWithSortable fixes this, but doesn't allow you to customize active/hoverClass options
$( this ).removeClass( "ui-state-default" );
}
});
After referenced the JQuery UI Droppable example : Shopping cart. I rewrite it for a test.But got some problem.
Suppose that :
product container: drag and drop the product into shopping cart container.
<div class="products">
<ul>
<li> product 1 </li>
...
</ul>
</div>
and shopping cart container:
<div class="shoppingCart1">
... dropped products here
</div>
and others shopping cart container:
<div class="shoppingCar2">
... dropped products here
</div>
And I want the shoppingCart1's products can drag and drop to other shopping cart container but not itself,and vice versa.E.g:
the problem is:
When the products had been dropped in s*hoppingCart1*, and then I can drag and drop the products in shoppingCart1 to other shopping cart container.But it seems that when I drag and drop the products inside of its own, it also append the products. I mean when I drag the shoppingCart1's product and drop in shoppingCart1 itself,it appended to shoppingCart1,too.
Thank you very much!
part of my code re-write from JQuery UI Droppable :shopping cart exmaple![ doesn't work as my want ]
this.igtoMDMovieList = $('<div />',{'class':'igtoMDMovieList'})
.appendTo(this.igtoMDMovieListWrapper);
this.igtoMDMovieListOL = $('<ol />',{'class':'igtoMDMovieListOL'})
.html('<li class="placeholder">Add your items here</li>')
.appendTo(this.igtoMDMovieList)
.droppable({
accept:'li',
drop: function( event, ui ) {
$( "<li></li>" )
.text( ui.draggable.text() )
.appendTo(obj.igtoMDMovieListOL)//$(this).children()
.draggable({
appendTo: "#desktopFrame",
helper: "clone"
})
}
})
.sortable({
items: "li:not(.placeholder)",
sort: function() {
// gets added unintentionally by droppable interacting with sortable
// using connectWithSortable fixes this, but doesn't allow you to customize active/hoverClass options
$( this ).removeClass( "ui-state-default" );
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这将确保任何列表中的内容都不会重复。
它使用
data-id
属性为每个产品提供一个产品 ID。示例: http://jsfiddle.net/petersendidit/S4QgX/
This will make sure things don't get duplicated in any list.
It uses the
data-id
attribute to give each product a product id.Example: http://jsfiddle.net/petersendidit/S4QgX/