1. Sitecore Content Hub

選択イベントを活用してください

日本語翻訳に関する免責事項

このページの翻訳はAIによって自動的に行われました。可能な限り正確な翻訳を心掛けていますが、原文と異なる表現や解釈が含まれる場合があります。正確で公式な情報については、必ず英語の原文をご参照ください。

以下のReact例はSELECTION_CHANGEDイベントの使い方を示しています。

import ReactDOM from "react-dom"; import React from "react";

interface Context { api: { selection: { addToSelection: ( ids: Array, selectionPoolIdentifier: string, subPoolId?: number ) => void; removeFromSelection: ( ids: Array, selectionPoolIdentifier: string, subPoolId?: number ) => void; clearSelection: ( selectionPoolIdentifier: string, subPoolId?: number, definitionNames?: Array ) => void; }; }; }

const onSelectionChanged = (evt: Event): void => { const { selectionPoolIdentifier, subPoolId, action, ids, definitionNames } = ( evt as CustomEvent<{ selectionPoolIdentifier: string; subPoolId?: number; action: "add" | "remove" | "clear"; ids?: Array; definitionNames: Array; }> ).detail;

alert( `selectionPoolIdentifier: ${selectionPoolIdentifier}, subPoolId: ${subPoolId}, action: ${action}, ids: ${ids}, definitionNames: ${definitionNames}` ); };

window.addEventListener("SELECTION_CHANGED", onSelectionChanged);

export default function createExternalRoot(container: HTMLElement) { return { render(context: Context) { const { addToSelection, removeFromSelection, clearSelection } = context.api.selection; const idsToAdd = 33379, 33380, 33378; const idsToRemove = 33379; const subPoolId = 35760; const selectionPoolIdentifier = "SelectionPool.Collection"; const definitionNames = "M.Asset";

ReactDOM.render( <> <button onClick={() => { addToSelection(idsToAdd, selectionPoolIdentifier, subPoolId); }}

Add to selection <button onClick={() => { removeFromSelection( idsToRemove, selectionPoolIdentifier, subPoolId ); }}

Remove from selection <button onClick={() => { clearSelection( selectionPoolIdentifier, subPoolId, definitionNames ); }}

Clear selection </>, container ); }, unmount() { window.removeEventListener("SELECTION_CHANGED", onSelectionChanged); ReactDOM.unmountComponentAtNode(container); }, }; }

この記事を改善するための提案がある場合は、 お知らせください!