Wie kann ich die ID des angeschlossenen Listenelements erhalten?
-
10-12-2019 - |
Frage
Ich habe drei angeschlossene ListView-Webteile auf einer Anwendungsseite, und ich möchte in der Lage sein, auf den in jedem Webpart ausgewählten Artikel zugreifen zu können.Dies ist nicht so ausgewählt wie in den Kontrollkästchen, sondern das angeschlossene Element, das den Filterwert an den nächsten Webpart angibt.Ich habe versucht generasacodicetagpre.
und praktisch alle anderen Eigenschaften meines Webparts.Gibt es keine Möglichkeit, die ID des angeschlossenen Artikels zu erhalten?
Lösung
I created three web parts connected together and filterable using Title:
Choose a color -> Choose a fruit -> View fruit details.
I created the following selector (jQuery required):
$('img[alt="Selected"]').parent().next().children('div.ms-vb');
Which returns an array of the selected elements which have an ID attribute. You could then do a simple each and do the work you want with each ID.
$('img[alt="Selected"]').parent().next().children('div.ms-vb').each(function(i){
console.log($(this).attr('id'));
});
// will give you:
// 3 (Blue)
// 2 (Blueberry)
Shows up like this in Chrome console:
I think this will work as long as the you use the Title (linked to item) column in the web parts.
Andere Tipps
If you use JSLink instead, I think you can connect to the items in the ListView Web Part like this:
- In a location of your choice (such as SiteAssets library of your site, or in _catalogs/masterpage), create new JavaScript file.
- In the file, add the code below
- In your web part, reference this JavaScript file in the JSLink setting, like ~/site/SiteAssets/news_ui.js
(function () {
// Initialize the variables for overrides objects
var overrideCtx = {};
overrideCtx.Templates = {};
overrideCtx.Templates.Fields = {
'ID': { 'ItemID' : ctx.CurrentItem.ID }
};
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
})();
Reference: