Bežný prípad použitia je navigácia na stránku vyhľadávania pomocou dynamického vyhľadávacieho dopytu pri kliknutí na prepojenie v rozložení obsahu.
Predpokladajme napríklad, že po kliknutí na prepojenie "More articles from this author" (Ďalšie články od tohto autora) v rozložení obsahu chcete prejsť na stránku vyhľadávania s názvom "Authors" (Autori), pričom sa odošle payload vyhľadávania. Dosiahnete to pomocou nasledujúceho kódu. Globálne objekty SCS
a SCSRenderAPI
sú k dispozícii na použitie v rozložení obsahu pri spustení vo vnútri stránky lokality.
$('.more-from-author').click($.proxy(function () { var childrenPages = SCS.structureMap[SCS.navigationRoot].children; if (!childrenPages) return; // No pages // Find the Authors page for (var i = 0; i < childrenPages.length; i++) { var page = SCS.structureMap[childrenPages[i]]; if (page.name === 'Authors') { var linkData = SCSRenderAPI.getPageLinkData(page.id); if (linkData && linkData.href) { var href = linkData.href, searchPayload = content.author_id + '*', contentType = "Starter-Blog-Post"; // if both the page URL and the search query exists, navigate to the page passing in the query if (href && searchPayload) { var queryStart = href.indexOf('?') === -1 ? '?' : '&'; // add in the contentType and search parameters // contentType isn't a required URL parameter // Payload contains search string only. No parameter name. href += queryStart + (contentType ? 'contentType=' + contentType + '&' : '') + 'q=' + searchPayload; // navigate to the search results page window.location = href; } } } } }, this));
Ak predpokladáte, že to isté rozloženie obsahu sa na tej istej stránke použije viackrát, je lepšie použiť jednoznačné ID v selektore CSS, nie selektor triedy, napríklad $('.more-from-author').click(…)
.
Príklad:
template.html <div id="{{navigateId}}">….</div> render.js content.navigateId = this.scsData.id + 'detailTrigger'; $('#' + navigateId).click(…)