我有一個包含所謂portlet(jQuery)的頁面。我想要一個按鈕來打開一個包含所有portlet數據的對話框(包括包含它們的列的id)。如何獲取頁面上的所有jQuery-portlet數據?
所以我想在對話框看起來像這樣:
COL1:
portlet標題:標題1
portlet內容:標題1的內容..
門戶標題:標題2
portlet內容:山雀內容LE2 ..
COL2:
portlet標題:TIIIIITLE
portlet內容:TIIIIITLE
的內容portlet標題:TIIIIITLE22121
portlet內容:的TIIIIITLE2212
內容或類似的東西噸。重要的部分是如何訪問Portlet數據。
編輯:我添加了這個jquery(和下面的一些html),它打開了一個對話框的portlet數據,只是它沒有做我想做的。如果我有2個標題/內容(a/1)&(b/2)的portlet並打開對話框,我得到:ab 12 ab 12.我想要:a 1 b 2.下面的行是需要的要更改,我想在每個語句中使用當前portlet的標頭/內容。
allContent += $(".portlet-header").text() + '\n' + $(".portlet-content").text() + '\n\n';
更多新的jQuery
$("#dialog-form-html").dialog({
autoOpen: false,
height: 600,
width: 400,
modal: true,
buttons: {
Cancel: function() {
$(this).dialog("close");
}
},
close: function() {
}
});
$("#get-html")
.button()
.click(function() {
var allContent = "";
$(".portlet").each(function(){
allContent += $(".portlet-header").text() + '\n' + $(".portlet-content").text() + '\n\n';
});
$("#dialog-form-html").text(allContent);
$("#dialog-form-html").dialog("open");
});
jQuery代碼:
<script type="text/javascript">
$(function() {
var title = $("#title"),
content = $("#content"), column = $("#column");
$("#dialog-form").dialog({
autoOpen: false,
height: 300,
width: 350,
modal: true,
buttons: {
"Add content": function() {
if(column.val()=='col1'){
$("#col1").append($('<div class="portlet ui-widget ui-widget-content ui-helper-clearfix ui-corner-all">' +
'<div class="portlet-header ui-widget-header ui-corner-all">' +
'<span class="ui-icon ui-icon-minusthick"></span>' + title.val() + '</div>' +
'<div class="portlet-content">' + content.val() + '</div></div>'))
$(this).dialog("close");
}
else if(column.val()=='col2'){
$("#col2").append($('<div class="portlet ui-widget ui-widget-content ui-helper-clearfix ui-corner-all">' +
'<div class="portlet-header ui-widget-header ui-corner-all">' +
'<span class="ui-icon ui-icon-minusthick"></span>' + title.val() + '</div>' +
'<div class="portlet-content">' + content.val() + '</div></div>'))
$(this).dialog("close");
}
else if(column.val()=='col3'){
$("#col3").append($('<div class="portlet ui-widget ui-widget-content ui-helper-clearfix ui-corner-all">' +
'<div class="portlet-header ui-widget-header ui-corner-all">' +
'<span class="ui-icon ui-icon-minusthick"></span>' + title.val() + '</div>' +
'<div class="portlet-content">' + content.val() + '</div></div>'))
$(this).dialog("close");
}
else if(column.val()=='col4'){
$("#col4").append($('<div class="portlet ui-widget ui-widget-content ui-helper-clearfix ui-corner-all">' +
'<div class="portlet-header ui-widget-header ui-corner-all">' +
'<span class="ui-icon ui-icon-minusthick"></span>' + title.val() + '</div>' +
'<div class="portlet-content">' + content.val() + '</div></div>'))
$(this).dialog("close");
}
else{
$("#tempcol").append($('<div class="portlet ui-widget ui-widget-content ui-helper-clearfix ui-corner-all">' +
'<div class="portlet-header ui-widget-header ui-corner-all">' +
'<span class="ui-icon ui-icon-minusthick"></span>' + title.val() + '</div>' +
'<div class="portlet-content">' + content.val() + '</div></div>'))
$(this).dialog("close");
}
},
Cancel: function() {
$(this).dialog("close");
}
},
close: function() {
//test();
}
});
$("#add-content")
.button()
.click(function() {
$("#dialog-form").dialog("open");
});
$(".column").sortable({
connectWith: ".column"
});
$(".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");
$(".column").disableSelection();
$("#centered").on('click', ".portlet-header .ui-icon", function() {
$(this).toggleClass("ui-icon-minusthick").toggleClass("ui-icon-plusthick");
$(this).parents(".portlet:first").find(".portlet-content").toggle();
});
});
</script>
編輯:我還添加了這個網站的新對話框:
3210HTML:
<body>
<div id="centered">
<div id="inset">
<h1>HALLÅ EKONOMEN</h1>
<div id="linear" style="padding: 20px"></div>
</div>
<div id="dialog-form" title="Create new user">
<p class="validateTips">All form fields are required.</p>
<form>
<fieldset>
<label for="title">Title</label>
<input type="text" name="title" id="title" class="text ui-widget-content ui-corner-all" />
<label for="content">Content</label>
<input type="text" name="content" id="content" value="" class="text ui-widget-content ui-corner-all" />
<label for="column">Column</label>
<select name="column" id="column" class="ui-spinner-down ui-widget-content ui-corner-all">
<option value="col1">left sidebar</option>
<option value="col2">main</option>
<option value="col3">bottom left</option>
<option value="col4">bottom right</option>
</select>
</fieldset>
</form>
</div>
<button id="add-content" >Add Content</button>
<div id="preview">
<table>
<tbody>
<tr>
<!--sidebar-->
<td>
<div id="col1" class="column">
</div>
</td>
<!--sidebar end-->
<td>
<table>
<tbody>
<!--main-->
<tr>
<div id="col2" class="column">
</div>
</tr>
<!--main end-->
<!--bottom colums-->
<tr>
<td style="border-left: 0px; border-bottom: 0px">
<div id="col3" class="column">
</div>
</td>
<td style="border-right: 0px; border-bottom: 0px">
<div id="col4" class="column">
</div>
</td>
</tr>
<!--bottom colums end-->
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
Trash column:<br /><br /><br />
<div id="trashcol" class="column">
</div>
</div>
</div>
</body>