我正在尝试在登录时为用户创建标准个人资料页面。我正在尝试传递变量(电子邮件)。我完全不知道如何将此变量传递到快速路由,因为它需要通过获取路由来完成,因为它正在拉回数据。
这就是我所拥有的。
使用 fetch 的地方。
正如您所看到的,我正在尝试通过此处发送可变电子邮件。
getItems() {
try {
const email = window.localStorage.getItem("User");
const data = { email };
fetch("/profile-account-details", email)
.then(recordset => recordset.json())
.then(results => {
this.setState({ AccountDetails: results.recordset });
});
} catch (e) {
console.log(e);
}
}
Run Code Online (Sandbox Code Playgroud)
通过我的 server.js 文件获取的路径。我只是需要将其与存储过程一起使用。我所需要的基本上就是变量在这里可用。
app.get("/profile-account-details", function(req, res) {
// connect to your database
sql.connect(config, function(err) {
if (err) console.log(err);
// create Request object
var request = new sql.Request();
// query to the database and get the records
request.execute("dbo.ProfileAccountDetails", function(err, recordset) { …Run Code Online (Sandbox Code Playgroud) 我之前已经将道具传递到不同的组件和页面,但这已经通过链接或只是将这些添加到组件标签本身。
我在这里遇到的问题是重定向不是通过链接标签或组件标签,而是我只是使用 window.locatio.href ="whatever the url is"。
我只是想将一个变量传递给这个(我在这种情况下在技术上进行了刷新,因此 window.location.reload() 也可以在可能的情况下工作)。
我将如何通过这个变量。使用 express 时,您可以使用类似于(可能不是确切的语法)“./page${variableYouWant}”的端点执行 fetch 语句,然后使用 req.params.variableYouWant 访问 express 文件。
是否可以通过这种方式传递变量,然后我将如何访问它。
这是我的代码中最重要的片段。
pageRelocator(mssg) {
if (mssg.length < 35) {
toast.info(`${mssg}`, {
draggable: true,
autoClose: 1500
});
window.location.href = "http://localhost:3000/completed-assessment";
} else if (mssg.length > 35) {
toast.error(`${mssg}`, {
draggable: true,
autoClose: 1500
});
//Here I would like to pass a variable
window.location.href = "http://localhost:3000/user-questions";
}
}
Run Code Online (Sandbox Code Playgroud)
编辑 -
componentDidMount() {
const search = this.props.location.mssg;
alert(search); // returns the URL query String …Run Code Online (Sandbox Code Playgroud) 我有一个基本的映射函数,它只是从数据库中进行基本的提取。我想要做的就是一旦获取就将其全部显示在屏幕上。
这是我收到的错误
×
TypeError: Cannot read property 'state' of undefined
(anonymous function)
C:/Users/Henry Peters/Codestone%20Workstation%20Self-Assessment%20Portal%202/src/Components/PageDetails/CompletedAssessments/CompletedAssessments.js:211
208 | return (
209 | <div >
210 |
> 211 | <li> {this.state.selectedSet.RUId}</li>
| ^ 212 | <li> <b>{this.state.selectedSet.QuestionId}</b></li>
213 |
214 | </div>
Run Code Online (Sandbox Code Playgroud)
这是我的班级
class Questions extends React.Component {
constructor(props) {
super(props);
console.log(props);
this.state = { ...props, };
this.checker = this.checker.bind(this)
}
checker( ){
this.setState({viewDetails : true})
let workStation = window.localStorage.getItem("Workstation")
let date = this.state.questions.Date
let email = window.localStorage.getItem("User")
fetch(`/show-questions-answered/${date}/${workStation}/${email}`)
.then(recordset => recordset.json()) …Run Code Online (Sandbox Code Playgroud) 这是一个基本的 c# 应用程序,但我很生疏。我将开始向您展示我的代码
using System;
using System.Data.SqlClient;
using System.Text;
namespace DatabaseAdder
{
class Program
{
static void Main(string[] args)
{
int RUId = 0;
int QuestionId = 0;
DateTime Date = DateTime.Now;
string QuestionWhenAnswered ;
string QuestionResponse;
int Accepted;
string AssignedWorkStation;
string CompleteToken;
try
{for (int i = 0; i < 300; i++) {
QuestionId ++;
QuestionIncrementInSetsOfTwelve(QuestionId);
Console.WriteLine(i );
Console.WriteLine( QuestionId);
Random rand = new Random();
// Build connection string
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
builder.DataSource = "localhost"; // update …Run Code Online (Sandbox Code Playgroud) 我正在制作一个基本的Visual Studio 项目。最简单的解释方法是显示代码。
using System;
using System.Collections.Generic;
namespace testing
{
class Program
{
static void Main(string[] args)
{
int amountOfCars = getAmountOfCars();
Car[] myCars = createCars(amountOfCars);
}
public static int getAmountOfCars (){
Console.WriteLine("Amount of Cars to enter");
int amountOfCars = Convert.ToInt32(Console.ReadLine());
return amountOfCars;
}
public static Car createCars(int amountOfCars)
{
Car[] myCars = new Car[amountOfCars];
for (int i = 0; i < amountOfCars; i++)
{
Console.WriteLine("Enter brand");
string brand = Convert.ToString(Console.ReadLine());
Console.WriteLine("Enter amount of wheels");
int amountOfWheels = …Run Code Online (Sandbox Code Playgroud)