我有一个场景,我需要将 sharepoint 列表绑定到动态创建的 html 表,并在内容编辑器 webpart 中使用 jquery 在站点中显示该表。请在这方面帮助我。我正在使用 sharepoint 2010。提前致谢。
我在这里尝试了一些东西,但没有运气,请帮我解决这个问题。谢谢enter code here
<script type="text/javascript" language="javascript">
var _clientContext;
var _web;
alert("Working")
//ExecuteOrDelayUntilScriptLoaded(RetrieveListItems, "sp.js");
function RetrieveListItems() {
alert("Test");
_clientContext = new SP.ClientContext.get_current();
alert(Context);
_web = _clientContext.get_web();
alert(web);
var list = _web.get_lists().getByTitle('Planning Partners');
alert(list);
// var camlQuery = new SP.CamlQuery();
var myquery = new SP.CamlQuery.createAllItemsQuery();
allItems = list.getItems(myquery);
_clientContext.load(allItems);
_clientContext.executeQueryAsync(Function.createDelegate(this, this.success), Function.createDelegate(this, this.failed));
}
function success() {
var Image = null;
var Linkurl = null;
var Title = null;
// var sHtml = "";
alert("success");
var ListEnumerator = this.allItems.getEnumerator();
while (ListEnumerator.moveNext()) {
var currentItem = ListEnumerator.get_current();
Image = currentItem.get_item('Image');
Linkurl = currentItem.get_item('Linkurl');
Title = currentItem.get_item('Title');
//var tbl = document.createElement("tbl");
var row = document.createElement("tr");
var $table = $('<table>');
$table.append('<caption>MyTable</caption>')
$table.append('<thead>');
$table.append('<tr>');
if (Image != oListItem.get_item('Image')) {
var cell = document.createElement("td");
var cellText = document.createElement("<image imgurl='" + oListItem.get_item('Image') + "'></Image>");
cell.appendChild(cellText);
row.appendChild(cell);
}
if (Linkurl != oListItem.get_item('Linkurl')) {
var cell = document.createElement("td");
var cellText = document.createElement("<a target='_blank' href ='" + oListItem.get_item('Linkurl') + "'>" + oListItem.get_item('Title') + "</a>");
cell.appendChild(cellText);
row.appendChild(cell);
}
if (Title != oListItem.get_item('Title')) {
var cell = document.createElement("td");
var cellText = document.createElement("<p>" + Title + "</p>");
cell.appendChild(cellText);
row.appendChild(cell);
}
$table.append('</tr>');
$table.append('</thead>');
tblBody.appendChild(row);
tbl.appendChild(tblBody);
body.appendchild(tbl);
}
}
// sHtml += '<table><tr><td><img src="' + Image + '" height="55px" width="55px"></td><td><table><tr><td valign="top"><div class="fieldsTitle">' + Linkurl + '</div></td></tr><tr><td valign="top">' + Title + '<a href="/">Read More >></a></td></tr><tr><td></td></tr></table></td></tr></table>';
// document.getElementById('MainDiv').innerHTML = sHtml;
// }
function failed(sender, args) {
alert("failed Message" + args.gte_message());
}
</script>