我想在VSCode 中添加一些自定义React.js代码片段。我意识到VSCode 中有两个文件。javascript.json和javascriptreact.json。javascript.json工作得很好,但是当我将代码片段移动到javascriptreact.json 时,VSCode无法识别它们。
如果我可以在javacriptreact.json文件中隔离这些片段,那就太好了,因为我也编写了服务器端 JavaScript。
我猜VSCode不会将该应用程序识别为 React 应用程序。有没有什么办法解决这一问题?
我从开放的API获取用户数据,将其存储在本地存储中,可以显示所有数据,但是只有第一个值被保存在本地存储中。如何存储所有数据?
我的代码:
String.prototype.capitalize = function() {
return this.charAt(0).toUpperCase() + this.slice(1);
}
function createNode(element) {
return document.createElement(element);
}
function append(parent, element ) {
return parent.appendChild(element);
}
const ul = document.getElementById('authors');
const url = 'https://randomuser.me/api/?results=10';
fetch(url)
.then((resp) => resp.json())
.then(function(data) {
let authors = data.results;
return authors.map(function(author) {
const myObj = {
name: `${author.name.first}`,
lastname : `${author.name.last}`,
email : `${author.email}`,
location : `${author.location.city}, ${author.location.street}`,
phone : `${author.phone}`
}
let li = createNode('li'),
img = createNode('img'),
span = createNode('span');
let myObj_serialized = JSON.stringify(myObj); …Run Code Online (Sandbox Code Playgroud) 我正在尝试向我的网站添加类似功能。我用以下模式制作了一个喜欢的集合。我使用自定义 _id 来避免创建额外的索引。
{
_id: {
postId: ObjectId,
userId: ObjectId
}
}
Run Code Online (Sandbox Code Playgroud)
我的服务器上有一个路由,它使用 MongoDB聚合搜索帖子集合。我正在尝试向当前管道添加一个$lookup阶段,以便添加一个带有布尔类型的喜欢属性,指示用户是否喜欢该帖子。这里的$查找未工作阶段(喜欢返回一个空数组全偶的时候有一个相应的像文件):
{
$lookup: {
from: 'likes',
let: { likedPostId: '$_id.postId', likerUserId: '$_id.userId' },
pipeline: [
{ $match:
{ $expr:
{ $and:
[
{ $eq: [
'$$likerUserId',
ObjectId('12345')
]},
{ $eq: [
'$$likedPostId',
'$_id'
]}
]
}
}
}
}
],
as: 'liked'
}
}
Run Code Online (Sandbox Code Playgroud)
我认为问题在于变量实际上并不包含我期望的值。有没有办法解决这个问题?另外,如果您知道一种更简单的方法来实现这一点,如果您与我分享,我将不胜感激。
我尝试比较两个相同的ObjectId()实例以确保可以使用$eq …