Question

This is a follow up question to the one i asked earlier : Reading web part properties using javascript object model

In my earlier question I had been able to access the properties using jsom but i am unable to target a particular web part without knowing its ID before hand. Inspecting the DOM i have found the below html. Here, the attribute webpartid is supposed to be used while performing a getById(GUID) call.

<div id="WebPartctl00_ctl35_g_a70dc106_4ee6_4a5d_9d85_95a2aabcffb1" webpartid2="a70dc106-4ee6-4a5d-9d85-95a2aabcffb1" webpartid="5f8931ff-a930-4942-be06-0fe948ad8c4c">

It would be great if anyone could help me out. Thanks in advance.

Était-ce utile?

La solution

You can use jQuery (or even plain JavaScript) to get the attribute from the generated for the wev part.

The only thing you'd need is somethint that allows you to identify this Web Part even from within the main container.

If you own the code for the WP, you can add a custom div with and ID or a class (or data-something), get that using jQuery and then navigate to thr parent container and get the webpartid property.

If it's an OOB web part you need to identify something unique about it, such as a special ID, class, etc. And follow the same logic.

Additionally, please review the following post as it explains how to get ALL the WPs in the page, so you could easily find it on the collection using JavaScript.

https://msdn.microsoft.com/en-us/library/office/hh185010%28v=office.14%29.aspx

Autres conseils

Hi Tanmay Your Web Part will have an element attribute called webpartid so you can use this to select all Web Parts, like this (jQuery):

$('[webpartid]');
Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top