2010-08-02 54 views
1

如何將jQuery UI Portlet添加到現有的Portlet集合中?jQuery如何添加portlet

(檢查:http://jqueryui.com/demos/sortable/portlets.html

加載後如何添加一個portlet?

在我的個人項目中,我實現了portlet:http://www.soliman.nl/test/jqueryui/ui_2.php 我想創建一個按鈕來追加一個portlet。我嘗試將它追加到.column,但CSS沒有加載(當然),當你.addClass時,所有其他portlet也受到影響。必須有一個簡單的方法......但如何?

+0

時發生了什麼你'.addClass'?你能否取消在你的網頁上的評論,以便我們可以目睹錯誤? (當我在添加新div後執行代碼時,其他portlet不受影響。)順便說一下,很棒的評論,只有第一個有點苛刻。 – MvanGeest 2010-08-02 20:38:18

+0

嗨。所有其他Portlet都會得到一個減號( - )以便最小化。 – Soliman 2010-08-02 20:42:18

+0

感謝您的補充,忘記了第一個:)。刪除了評論星。 – Soliman 2010-08-02 20:43:25

回答

1

目前,你在做

$(".portlet").addClass("ui-widget ui-widget-content ui-helper-clearfix ui-corner-all") 
.find(".portlet-header") 
.addClass("ui-widget-header ui-corner-all") 
.prepend('<span class="ui-icon ui-icon-minusthick"></span>') 
.end() 
.find(".portlet-content"); 

如果什麼你擺脫$(".portlet")的同時繼續使用$(".addspace")你有的replaceWith之前,這樣的嗎?

$('.addspace').replaceWith(html) 
.addClass("ui-widget ui-widget-content ui-helper-clearfix ui-corner-all") 
.find(".portlet-header") 
.addClass("ui-widget-header ui-corner-all") 
.prepend('<span class="ui-icon ui-icon-minusthick"></span>') 
.end() 
.find(".portlet-content"); 
+0

CSS不追加... – Soliman 2010-08-02 20:56:38

+0

啊..但附加,而不是replaceWith工作! – Soliman 2010-08-02 21:13:41

+0

但是現在,您的portlet停留在addspace中。您將無法添加第二個... – MvanGeest 2010-08-02 21:25:59

0

在創建幾個portlet之後,添加帶有類addspace的最後一個div。

然後用.replaceWith和.addClass創建一個函數。返回的HTML的

$('.addspace').replaceWith(html); 

例子:

<div class="portlet" id="portletname"> <!-- make sure portletname is unique --> 
<div class="portlet-header">test</div> 
<div class="portlet-content">test</div> 
</div> 

<!-- New addspace (replaceWith replaces the old one) --> 
<div class="addspace" > 
</div 

添加portlet類按ID的div:

$('#portletname') 
     .addClass("ui-widget ui-widget-content ui-helper-clearfix ui-corner-all") 
     .find(".portlet-header") 
     .addClass("ui-widget-header ui-corner-all") 
     .prepend('<span class="ui-icon ui-icon-minusthick"></span>') 
     .end() 
     .find(".portlet-content");