如何解决this.appendChild (articleItemElement) 上的 this 关键字;指的是?
简而言之,我有一个 javascript 文件,其中包含一个数据数组,其中有 4 个对象,每个对象由 4 个属性组成,然后第二个文件是...
============================================
(article-item.js)
class ArticleItem extends HTMLElement {
set article(article) {
this._article = article;
this.render();
}
render() {
this.innerHTML = `
<img class="featured-image" src="${this._article.featuredImage}">
<div class="article-info">
<h2><a href="${this._article.id}">${this._article.title}</a></h2>
<p>${this._article.description}</p>
</div>
`;
}
}
customElements.define("article-item",ArticleItem);
================================================ ======
(article-list.js)
import "./article-item.js"
class ArticleList extends HTMLElement {
set articles(articles) {
this._articles = articles;
this.render();
}
render() {
this._articles.forEach(article => {
const articleItemElement = document.createElement("article-item");
// memanggil fungsi setter article() pada article-item.
articleItemElement.article = article;
this.appendChild(articleItemElement);
})
}
}
customElements.define("article-list",ArticleList);
================================================ ==============
今天我在学习嵌套自定义元素,我非常了解程序流程是如何运行的。但是有些部分我还是不明白,比如这行/关键字 this 在 (this.appendChild (articleItemElement);) 中做了什么,然后在 (articleItemElement.article = article;) 中我明白我只能分配数据如果使用访问器属性或 getter / setter 技术,可以通过访问 .article 属性通过 JavaScript 语法自定义元素。部分(=文章)的功能是什么?或者如果我错了,请解释该行的功能
我真的希望并感谢有人为我解释这一点
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。