运行以下查询时出现上述错误。我以前没有见过它,找不到任何关于它的文档,而且我没有做任何不寻常的事情或我以前没有做过的任何事情。任何人都可以对此有所了解吗?
const getUserProjects = async () => {
return await useFireStore
.collection('projects')
.where('paid','==',true)
.where('ownerId','==', `${currentUser.uid}`)
.orderBy('createdAt', 'desc')
.onSnapshot(snapshot => {
let projects = [];
snapshot.forEach(doc => {
projects.push({...doc.data(), id: doc.id })
});
setUserProjects(projects);
});
};
Run Code Online (Sandbox Code Playgroud)
这是一个“新”查询,因为我刚刚将它添加到代码中,所以我可能期望控制台中的错误提供了一个链接,用于创建一个新的复合索引或任何它被调用的名称,但我只是得到这个:
编辑:我尝试手动创建索引,但仍然遇到相同的错误。我也在同一页面上得到了一个查询,除了集合名称之外,它完全相同,并且工作正常。
我有一个不知道高度的 flex-col 容器。我应该能够在容器中使用 justify- Between 来分隔两个 div,一个到 div 的顶部,一个到底部,因为它的主轴被定义为垂直,并且 justify- Between 用于“对齐项目”根据文档,沿着容器\xe2\x80\x99s 主轴\'。
\n此代码水平工作:
\n<div class="w-screen h-screen bg-blue-200">\n <div class="flex justify-between">\n <div>1</div>\n <div>3</div>\n </div>\n</div>\nRun Code Online (Sandbox Code Playgroud)\n但是,如果我们将第二个 div 更改为“flex-col”,则 justify- Between 将无法沿垂直轴工作。为什么是这样?
\n<div class="w-screen h-screen bg-blue-200">\n <div class="flex flex-col justify-between">\n <div>1</div>\n <div>3</div>\n </div>\n</div>\nRun Code Online (Sandbox Code Playgroud)\n游乐场在这里: https://play.tailwindcss.com/41DdUFN3Fw
\n请问我怎样才能实现这个目标?
\n我在 React Native 中有一个 Animated.View,我正在为其宽度设置动画。
const pollRef = useRef(new Animated.Value(0)).current;
const resultWidth = ((votes/totalVotes)*100).toFixed(0) // GET A PERCENTAGE VALUE
const AnimateResult = () => {
Animated.timing(pollRef, {
toValue: resultWidth,
duration: 3000,
useNativeDriver: false
}).start();
};
useEffect(() => {
AnimateResult()
},[])
<Animated.View
style={{
position: 'absolute',
top: 0,
left: 0,
height: '100%',
width: pollRef,
backgroundColor: '#155A8B',
}}
/>
Run Code Online (Sandbox Code Playgroud)
resultWidth(因此 pollRef)的值是 100。元素的宽度动画效果很好,除了它正确地将 100 视为绝对值并将宽度动画化为 100 像素之外,而我想将其表示为百分比。无论我在样式对象中使用什么语法,我似乎都无法做到。
我尝试过类似的事情:
style={{
...
width: "'"+pollRef+"%'"
...
}}
Run Code Online (Sandbox Code Playgroud)
和
style={{
...
width: `${pollRef}%`,
...
}}
Run Code Online (Sandbox Code Playgroud)
但两者都不起作用。我还注意到变量周围似乎有空格 - 如果我控制台日志: …
我有以下功能反应组件,它可以在“边界”框中正确显示两个静态标记,该框适合两个标记。
我希望能够传递一系列纬度和经度值以供地图显示,但我不知道如何做到这一点。
这是工作的静态示例:
import React from 'react'
import { MapContainer, TileLayer, Marker } from 'react-leaflet'
import L from 'leaflet'
import 'leaflet/dist/leaflet.css'
const MapLeaflet = () => {
// STATIC MARKER POSITIONS
const position = [42.2974279, -85.628292];
const position2 = [-8.852507, -45.351563];
// BOUNDS CODE
const bounds = L.latLngBounds([position, position2]);
return (
<MapContainer
className=" map"
center={position}
bounds={bounds}
>
<Marker key={key} position={position}>
<Heart/>
</Marker>
<Marker key={key} position={position2}>
<Heart/>
</Marker>
<TileLayer
attribution='&copy <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/>
</MapContainer>
)
}
Run Code Online (Sandbox Code Playgroud)
如果我传递 is {coords} …
我有一个表单组件,用户可以在其中输入评论,还有一个单独的组件,可以映射并显示评论列表。提交评论后,只有在页面失去焦点然后重新获得焦点时才会显示评论。我怎样才能让新评论在提交时显示出来而不必首先失去焦点?
这是我的表单组件中的相关代码
import { useSWRConfig } from 'swr'
const { mutate } = useSWRConfig()
const postData = async (form) => {
setLoading(true);
await axios.post('/api/comments', form);
mutate('/api/comments');
setLoading(false);
}
Run Code Online (Sandbox Code Playgroud)
根据文档https://swr.vercel.app/docs/mutation “您可以从 useSWRConfig() 挂钩获取 mutate 函数,并通过调用 mutate(key) 使用相同的密钥向其他 SWR 挂钩全局广播重新验证消息)*"
这是显示评论的组件:
const Comments = ({ postId }) => {
const { comments, loading, error } = useComments(postId)
if (error) return <div>An terror has occurred</div>;
if (loading) return <div>Loading comments</div>;
return (
<div className="flex flex-col w-full space-y-2">
{comments && comments[0].map((comment) …Run Code Online (Sandbox Code Playgroud) 我有一个 React 组件,它必须对 MongoDB 数据库执行带有两个参数的 find({}) 查询。
const likes = await Likes.find({ postId: postId, userId: userId }).exec()
Run Code Online (Sandbox Code Playgroud)
由于 Mongo 代码只能在服务器上运行,所以我必须进行 API 调用(我正在使用 NextJS)。这个API调用显然是一个GET请求。如何使用 SWR(或 fetch)将“postId”和“userId”传递给获取请求?
我试图将它们作为对象通过“身体”传递,但我认为这根本不是正确的方法。
const likesPerUser = {
postId: postId,
userId: userId
}
const docs = await fetch('/api/likes/user', {
method: 'GET',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(likesPerUser),
})
Run Code Online (Sandbox Code Playgroud)
我无权访问 URL 查询字符串
我有一种感觉,我可能有点跑题了。任何帮助将非常感激。干杯,马特
对于这个非常基本的问题表示歉意,但我有点困惑。我在 Express + Node 服务器中使用 Mongoose 发布到 Mongo,我刚刚意识到这两个模型/模式与它们发布到的 MongoDB 中的集合名称不完全相同。一切正常,API 端点发布到正确的集合,但我不知道如何或为什么。Mongoose 模型/模式和 MongoDB 集合之间有什么联系?
显然,我的 MONGODB_URI 环境变量指向我的数据库,但没有其他对集合的引用,特别是 API 端点应发布到哪个集合,除了模型,它与集合的名称不同。
例如,下面我的Post模型确实将数据(通过 api)发送到posts集合,但我无法弄清楚它如何知道这是正确的集合,这让我很烦恼。
const PostSchema = new Schema({
...
});
const Post = mongoose.model('Post', PostSchema);
module.exports = Post;
Run Code Online (Sandbox Code Playgroud)
作为测试,我将上面的变量完全重命名为完全不相关的东西
const TrevorSchema = new Schema({
...
});
const Trevor = mongoose.model('Trevor', TrevorSchema);
module.exports = Trevor;
Run Code Online (Sandbox Code Playgroud)
并且创建了一个带有复数模型名称“Trevors”的新集合,那么 Mongoose 是否会查找要映射到的模型复数名称?干杯,马特
reactjs ×3
javascript ×2
mongodb ×2
next.js ×2
swr ×2
css ×1
firebase ×1
leaflet ×1
mongoose ×1
node.js ×1
react-native ×1
tailwind-css ×1