我有一个带有ListViewByQuery和Button控件的aspx站点。单击按钮后,我想从ListViewByQuery控件中获取所选项。我使用了以下代码,但变量“selection”的计数总是为0。
<asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
<script type="text/javascript">
$(document).ready(function () {
var button = $("input[id$=SaveButton]");
button.click(function () {
var context = SP.ClientContext.get_current();
var selection = SP.ListOperation.Selection.getSelectedItems(context);
var fileItems = [];
var currentItem;
for (currentItem in selectedItems) {
fileItems.push(currentItem);
context.load(currentItem, 'Id');
}
context.executeQueryAsync(Function.createDelegate(this, function () {
for (var i = 0; i < fileItems.length; i++) {
alert(fileItems[i].get_id());
}
}));
});
});
</script>
</asp:Content>
<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<div id="pnlDiv">
<SharePoint:ListViewByQuery runat="server" ID="MyListView" Enabled="True" />
<asp:Button ID="SaveButton" runat="server" Text="Button" />
</div>
</asp:Content>
<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">
Application Page
</asp:Content>
<asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea"
runat="server">
My Application Page
</asp:Content>
其他事实: - 列表从文件后面的代码中填充 - 在DL的编辑表单之后,事件接收器(“SPEventReceiverStatus.CancelWithRedirectUrl”)调用aspx站点。
答案 0 :(得分:0)
方法ListModule.Util.getSelectedItemsDict
(core.js
)可用于检索ListViewByQuery Control中的所选项目。
示例1 。
该示例演示了如何从“工作流历史记录”列表(wrkstat.aspx
)
function getSelectedItemsInfo(ctxNumber)
{
var listCtx = GetListContextFromContextNumber(ctxNumber);
return ListModule.Util.getSelectedItemsDict(listCtx);
}
//Note: Context Number for Workflow History list on page wrkstat.aspx is 2, since it contains 2 ListViewByQuery controls on the page. If page contains only single ListViewByQuery control then Context Number is 1
var selectedItems = getSelectedItemsInfo(2);
printItemsInfo(selectedItems);
function printItemsInfo(items)
{
if(!items)
return;
for (var key in items){
var item = items[key];
var itemId = item.id;
var itemType = item.fsObjType;
console.log(String.format('Selected List Item Id: {0}',itemId));
}
}
注意:识别
ListViewByQuery
控制上下文编号必须 被指定。对于“{1}}页面上的工作流程历史列表” 2,因为它在页面上包含2个wrkstat.aspx
控件。如果是页面 仅包含单个ListViewByQuery
控件,然后包含上下文编号 的 1 强>
示例2.
以下示例演示了如何从“工作流程历史记录”列表中的所选项目中检索ListItem集合(ListViewByQuery
)
wrkstat.aspx