给出以下示例代码:
import { LitElement, html, css } from 'lit-element';
class ItemsDisplay extends LitElement {
static get styles() {...}
static get properties {...}
constructor () {
super();
...
}
render {
return html`
${this.items.map((item, index, array) => html`
<div class="name">
...
</div>
`)}
`;
}
}
Run Code Online (Sandbox Code Playgroud)
选择类“name”的所有节点的适当方法是什么?
我尝试过以下方法,但均失败;所有时间nodesList都是undefined:
constructor : this.nodesList = this.shadowRoot.querySelectorAll(".name");
Run Code Online (Sandbox Code Playgroud)
firstUpdated(changedProperties) {
return this.nodesList = this.shadowRoot.querySelectorAll(".name");
}
Run Code Online (Sandbox Code Playgroud)
getNodesList() {
let nodesList = this.shadowRoot.querySelectorAll(".name");
...
}
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
connectedCallback() {
super.connectedCallback(); …Run Code Online (Sandbox Code Playgroud)