jQuery可排序Portlet+创建动态新Portlet
jQuery sortable portlets + creating dynamic new portlets
为了简化问题,让我们假设我们使用的代码与jquery ui portlet小部件完全相同:
http://jqueryui.com/sortable/#portlets
我在stackoverflow中读到了另一个关于主题的帖子,但它真的没有给我一个关于如何处理解决方案的线索,因为原始代码已经不可用了
jQuery如何添加portlet
让我们想象一下向现有列添加新portlet的最简单方法:
$( "#col0" ).append($('<div class="portlet ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" id="p5">' +
'<div class="portlet-header ui-widget-header ui-corner-all">' +
'<span class="ui-icon ui-icon-minusthick"></span>' + "my title" + '</div>' +
'<div class="portlet-content">' + "my content" + '</div></div>'))
使用这种方法,我必须解决一些重要问题:
标题右角的"+"按钮不适用于新的Portlet。
标题和内容文本不会保留在div内部。当文本到达div的边缘时,它会继续在外部。
我试图通过在stackoverflow中获得的这种方法来获得portlet的顺序。当您只使用默认的jqueryportlet加载应用程序时,它就可以工作了。
$( ".column" ).sortable({ connectWith: ".column", delay: 150, start: function(event, ui) { ui.item.startPos = ui.item.index(); item = ui.item; newList = oldList = ui.item.parent(); }, stop: function(event, ui) { /*saveOrder();*/ console.log("Start position: " + ui.item.startPos); console.log("New position: " + ui.item.index()); }, change: function(event,ui) { if(ui.sender) newList = ui.placeholder.parent();
},
在添加新portlet之前和之后,当我尝试获取可排序的列元素时:
$("#obtain").button().click(function() {
console.log($("#col0").sortable('toArray').toString());});
它为我提供了每列正确数量的元素(添加了新的元素(,但当我试图在列之间移动新的元素时,当你以普通的方式创建新元素时,列中的位置是没有意义的。我认为,每次创建新的portlet时,我都应该再次执行start((函数,这样我就可以获得正确的索引。但我不知道该怎么做。
非常感谢你抽出时间,我希望我能得到一些建议,
关于
对于#1我认为您错过了portlet切换类
<span class="ui-icon ui-icon-minusthick">
应该是
<span class='ui-icon ui-icon-minusthick portlet-toggle'>
相关文章:
- 无法从 jQuery RSS Feed 中的 localStorage 动态替换类
- 使用JS如何动态更改显示的html文件中的文本背景颜色
- 动态分配GA增强型电子商务跟踪器
- onkeyup无法动态创建多个文本区域
- 使用javascript将动态表从一个html页面打印到另一个html页
- 如何使Javascript动态html表及其上的事件
- 动态地改变“”的URL;添加新项目”;链接使用javascript/jquery
- 如何在Bootstrap Modal中为动态点击生成的变量设置jade属性
- 如何使用javascript从主svg对象动态创建svg视图框
- 试图在引导模式内动态生成图表,得到offsetWidth错误
- 通过在Dojo mobile ViewController.openExternalView中动态更改打开同一外部视图的
- 如何在Google柱状图中动态添加行/列
- 困在逻辑中试图定位动态的东西
- 在动态创建的元素上获取对特定选择器的引用
- 如何动态插入jquery代码
- 使用Google Visualization动态调用构造函数
- 使用jQuery动态添加表并在其中动态添加行
- d3基于用户选择动态更新节点
- 使用JQuery的动态上下文菜单
- jQuery可排序Portlet+创建动态新Portlet