問題文
A bicycle sharing service renders one child component per docking station inside a parent component. When the rider taps a row, the parent must know which station was chosen so it can show the bikes available there. Which implementation is correct?
選択肢
- Dispatch a CustomEvent from the child whose detail carries the station Id, and read event.detail in the parent's handler, because an event travels up to the component that placed the child in its own markup.
- Import the parent's module in the child and assign the station Id to a public property of the parent instance, and the parent reacts to the assignment.
- Publish the station Id on a message channel, because passing a value from a child to its own parent needs the message service whenever the value is an Id rather than a plain string.
- Dispatch a CustomEvent with no detail and let the parent read the child's private property through the shadow root once the event arrives, pulling the Id out.