[英]How to add HTML-tags to JS-file
I use Expo (React Native) with the main App.js
file.我将 Expo (React Native) 与主App.js
文件一起使用。 It's connected to my base with data called data.js
.它通过名为data.js
的数据连接到我的基地。 Example of data.js element: data.js 元素示例:
{
id: '70078463',
price: '$49.99',
name: 'PELLO',
image:
'https://www.ikea.com/us/en/images/products/pello-armchair__38296_PE130209_S5.JPG?f=xs'
},
I want to add a description
tag with the information about the item:我想添加一个description
标签,其中包含有关该项目的信息:
description: 'This is the best one you can buy online. It is so cool! Why have not you bought it?',
In HTML I could use <p>
tag to make each sentense on a new line.在 HTML 中,我可以使用<p>
标签将每个句子放在一个新行上。 How can I do it here?我怎么能在这里做呢?
To add a description to your JS Object as a new key-value pair you have two options:要将描述添加到您的 JS Object 作为新的键值对,您有两个选项:
let object = {
id: '70078463',
price: '$49.99',
name: 'PELLO',
image:
'https://www.ikea.com/us/en/images/products/pello-armchair__38296_PE130209_S5.JPG?f=xs'
},
Using Dot Notation :使用点符号:
object.description = "value";
Or Square Bracket Notation :或方括号表示法:
object["description"] = "value";
If you know for sure it is always description you can use dot notation but if you want to dynamically add key-value pairs the square bracket notation lets you pass in a variable.如果您确定它始终是描述,则可以使用点表示法,但如果您想动态添加键值对,方括号表示法允许您传入变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.