Get ID of Selected List Item

倖福魔咒の 提交于 2019-12-24 15:26:03

问题


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.

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]

Does anyone know how to get the ID of the selected list item or point me to the correct method to use in JavaScript?

Thanks!


回答1:


The issue is that items is a Dictionary type as described here: http://msdn.microsoft.com/en-us/library/ff409526(v=office.14).aspx

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;


来源:https://stackoverflow.com/questions/14738605/get-id-of-selected-list-item

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!