当我想在node.js html中显示来自Firestore的数据时,在以下两个代码上出现错误: productName.textContent = doc.data()。name; productPrice.textContent = doc.data()。price;
const myProducts = db.collection('products');
const productsContainer = document.querySelector('#groceries');
function renderProduct(doc) {
const docFrag = document.createDocumentFragment();
let article = document.createElement('article');
let productName = document.createElement('h4');
let productPrice = document.createElement('p');
article.setattribute('id',doc.id);
productName.textContent = doc.data().name;
productPrice.textContent = doc.data().price;
docFrag.appendChild(productName);
docFrag.appendChild(productPrice);
article.appendChild(docFrag);
productsContainer.appendChild(article);
}
myProducts.onsnapshot(products => {
products.forEach(doc => {
products = doc.data();
console.log(products);
renderProduct(products);
});
});
class shop extends React.Component {
render() {
return (
<div classname="app-wrapper">
<ContainerHeader match={this.props.match} title={<IntlMessages id="appModule.contactSupport"/>}/>
<div classname="d-flex justify-content-center">
<div id="groceries"></div>
</div>
</div>
);
}
}