英文:
How can i add hidden notes Functionality in an notes app made using MERN stack, in Mongoose(for mongodb)
问题
Sure, here's the translated content:
我想要添加一个隐藏笔记的功能,当我点击隐藏笔记按钮时,该笔记应该从当前位置移除并添加到隐藏笔记中。当我点击隐藏笔记时,我应该能够查看它们,并有选项取消隐藏。请帮忙。
这是我目前完成的网页(隐藏笔记按钮在所有笔记下拉菜单中):
这是到目前为止完成的笔记应用程序代码(Google Drive链接,不包括node_modules,因为它太大):
这是app.js的代码:
import './App.css';
import {
BrowserRouter as Router,
Routes,
Route,
Link
} from "react-router-dom";
import Navbar from './components/Navbar';
import Home from './components/Home';
import AddNote from "./components/AddNote"
import About from './components/About';
import NoteState from './context/notes/NoteState';
import Alert from './components/Alert';
import Footer from './components/Footer';
import DropDown from './components/DropDown';
function App() {
return (
<>
<NoteState>
<Router>
<Navbar />
<DropDown></DropDown>
<div className="container">
<Routes>
<Route exact path="/" element={<Home />} />
<Route exact path="/about" element={<About />} />
<Route exact path="/addnote" element={<AddNote/>} />
</Routes>
</div>
<Alert message="This is amazing React course" />
<Footer></Footer>
</Router>
</NoteState>
</>
);
}
export default App;
请帮忙。
英文:
I want to add a hidden notes funcionality in which when i click the hide note button the note should be removed from that place and get added to hidden notes, and when i click on hidden notes i should see them, and even get the option to unhide it, Please help,
Here is the webpage i currently have done(The button for hidden notes is in the all Notes dropdown):
Here is the code for the notes app done till now - (drive File), (without node_modules as it is very heavy):
this is app.js:
import './App.css';
import {
BrowserRouter as Router,
Routes,
Route,
Link
} from "react-router-dom";
import Navbar from './components/Navbar';
import Home from './components/Home';
import AddNote from "./components/AddNote"
import About from './components/About';
import NoteState from './context/notes/NoteState';
import Alert from './components/Alert';
import Footer from './components/Footer';
import DropDown from './components/DropDown';
function App() {
return (
<>
<NoteState>
<Router>
<Navbar />
<DropDown></DropDown>
<div className="container">
<Routes>
<Route exact path="/" element={<Home />} />
<Route exact path="/about" element={<About />} />
<Route exact path="/addnote" element={<AddNote/>} />
</Routes>
</div>
<Alert message="This is amazing React course" />
<Footer></Footer>
</Router>
</NoteState>
</>
);
}
export default App;
Please Help
答案1
得分: 1
-
创建一个名为"notes"的表格。
1.1. 这个表格应该有一个名为"isVisible"的字段。这个字段的数据类型将是布尔型,并且默认值设置为true。
-
创建一个API来改变笔记的可见性,方法应该是"PATCH"。
-
创建一个API来获取所有笔记的列表。在请求参数中,您需要添加一个参数,即isVisible,根据参数的值,API将返回数据。
例如,如果您想显示所有隐藏的笔记,那么您的后端URL将如下所示:http://localhost:3000/api/notes?isVisible=false
英文:
-
Create a table named "notes"
1.1. The table should have a field named "isVisible". The data type of this field will be boolean and by default the value is set to true.
-
Create an API to change the visibility of the note, the method should be "PATCH".
-
Create an API to fetch the list of all the notes. In request parameters you have to add one parameter i.e.,isVisible and based on the value of the parameter the API will return the data.
For example if you want to show all the hidden notes then your backend URL will look like http://localhost:3000/api/notes?isVisible=false
答案2
得分: 0
这取决于你希望如何保存数据,我通常会按照以下逻辑编写代码:
1)获取你想隐藏的项目的ID。
2)将项目ID添加到隐藏列表中(将其保存到数据库中)。
3)在加载笔记数据之前,你应该根据隐藏列表中存储的ID来过滤掉相应的ID。
let currNotesData = notesData.filter((notes) => {
return hiddenList.includes(notes);
})
4)然后,你可以遍历currNotesData
并渲染可用的组件。
这也有其他的方法可以做到。
英文:
It depends how you want to save the data, I would normally write the logic like this:
- get the id of the item you want to hide
- push the item id to the hidden list (save it to the database)
- before you load the notes data, you should filter out the id based on the id stored in the hidden list.
let currNotesData = notesData.filter((notes) => {
return hiddenList.includes(notes) })
- Then, you can loop through the currNotesData and render the available component.
There are more ways to do this too
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论