获取所选列表项的 ID [英] Get ID of Selected List Item
问题描述
我正在尝试使用 JavaScript 获取所选列表项的 ID.基本上,我试图使用 JavaScript 获取 ID,然后在同一个 JavaScript 中重定向到查询字符串中具有所选 ID 的页面.
I am trying to get the ID of a selected list item using JavaScript. Basically I am trying to get the ID using JavaScript and then in the same javascript redirect to a page with the selected ID in the querystring.
这是我的 javascript:
This is my javascript:
function GetID() {
var ctx = SP.ClientContext.get_current();
var items = SP.ListOperation.Selection.getSelectedItems(ctx);
window.location.href = "/_layouts/CustomApplicationPage/CustomApplicationPage.aspx?ID=" + items;
}
但我在查询字符串中得到的结果是:
But the results I get in my querystring are:
CustomApplicationPage.aspx?ID=[object Object]
有谁知道如何获取所选列表项的 ID 或指向我在 JavaScript 中使用的正确方法吗?
Does anyone know how to get the ID of the selected list item or point me to the correct method to use in JavaScript?
谢谢!
推荐答案
问题是 items
是一个 Dictionary
类型,如下所述:http://msdn.microsoft.com/en-us/library/ff409526(v=office.14).aspx
The issue is that items
is a Dictionary
type as described here:
http://msdn.microsoft.com/en-us/library/ff409526(v=office.14).aspx
由于您只是想取回单个值,因此您可以通过引用 Dictionary
中的第一个值来获得所需的内容.
Since you are only trying to get a single value back, you can likely get what you need by referencing the first value in the Dictionary
.
window.location.href = "/_layouts/CustomApplicationPage/CustomApplicationPage.aspx?ID=" + items[0].id;
这篇关于获取所选列表项的 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!