[英]Can I add a link inside an object value?
I have an object that I am using to store data I want available on my site, and I would like to add a link inside the value.我有一个对象用于存储我希望在我的站点上可用的数据,并且我想在该值中添加一个链接。 Example -
例子 -
s3: {
title: "Title",
description: "I want to describe a website and provide a link in here",
},
I want the "here" to be a link.我希望“这里”成为一个链接。
I've tried with the link() method -我已经尝试过使用 link() 方法 -
const linkName = "Here"
const link = linkName.link("http://www.google.com")
description: "I want to describe a website and provide a" + link + "in here",
but that just shows the literal HTML after I loop through the object and display it, not an actual link.但这只是在我遍历对象并显示它后显示文字 HTML,而不是实际链接。
*Edit - I am using React to display the data. *编辑 - 我正在使用 React 来显示数据。 Example -
例子 -
Object.keys(object).map(function (key) {
return <Card
title={object[key].title}
description={object[key].description}
/>;
});
nothing fancy about that at all...根本没有什么特别的......
s3: {
title: "Title",
description: "I want to describe a website and provide a link in here",
}
//any "link" is just a string that represents a url... thus just store it as a property=>String like so.
s3.link = "putYourUrlHere";
//or another way is in the declartion of the object literal.
s3: {
title: "Title",
description: "I want to describe a website and provide a link in here",
link: "putYourUrlHere";
}
//but then you have to generate html from an object.
//so maybe something like this?
s3: {
title: "Title",
descript1: "I want to describe a website and provide ",
descript2: " in here",
link: "putYourUrlHere";
}
const div = document.createElement('div');
const a = document.createElement('a');
a.setAttribute('src', s3.link);
const p1 = document.createElement('p');
const p2 = document.createElement('p');
p1.innerHTML = s3.descript1;
p2.innerHTML = s3.descript2;
div.appendChild(p1);
div.appendChild(a);
div.appendChild(p2);
//that's if you want it in the middle, or a specific part of the description.
edit: fixed concatenation error编辑:固定连接错误
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.