2 loops to insert data in my database(mysql) using reactjs(frontend) and nodejs/expressjs(backend)
up vote
0
down vote
favorite
I am stuck trying to insert 2 values in an object that has 2 arrays in it. I tried looping through the 1st object, then the 2nd, but whenever I insert the data, it only inserts the value (the second loop)at index 0 instead of inserting the value at index 0,1 and so on. For example, it would only insert the value Air Canada instead of inserting Air canada and Air Canada Rouge
Here is the code and picture below to view the JSON file in order to get a better picture of my problem (the yellow highlights in my picture are the key things to look for)
Code (React)
addClosedCRs = _ => {
this.state.jiraCLOSEDCRsAccepted.issues && Object.keys(this.state.jiraCLOSEDCRsAccepted.issues).map((issue, i) => (
this.state.jiraCLOSEDCRsAccepted.issues && this.state.jiraCLOSEDCRsAccepted.issues[i].fields && this.state.jiraCLOSEDCRsAccepted.issues[i].fields.customfield_11400 && Object.keys(this.state.jiraCLOSEDCRsAccepted.issues[i].fields.customfield_11400).map((field, customfield_11400_index) => (
fetch(`http://ca-fpscfb2:2000/ClosedCRs/add?supNumber=${this.state.jiraCLOSEDCRsAccepted.issues[i].key}&Airline=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.customfield_11400[customfield_11400_index].value}&Product=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.customfield_11600.value}&Title=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.summary}&Status=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.status.name}&DateCRRequestReceived=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.created.slice(0, 10)}&EcrNumber=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.customfield_10800}&supNumberLink=<div><a target="_blank" href="http://ksr-ca-qmaltjira.ca.kronos.com:8061/browse/${this.state.jiraCLOSEDCRsAccepted.issues[i].key}">${this.state.jiraCLOSEDCRsAccepted.issues[i].key}</a></div>`)
))
))
}
componentDidMount(){
this.addClosedCRs();
}
mysql node.js reactjs express
add a comment |
up vote
0
down vote
favorite
I am stuck trying to insert 2 values in an object that has 2 arrays in it. I tried looping through the 1st object, then the 2nd, but whenever I insert the data, it only inserts the value (the second loop)at index 0 instead of inserting the value at index 0,1 and so on. For example, it would only insert the value Air Canada instead of inserting Air canada and Air Canada Rouge
Here is the code and picture below to view the JSON file in order to get a better picture of my problem (the yellow highlights in my picture are the key things to look for)
Code (React)
addClosedCRs = _ => {
this.state.jiraCLOSEDCRsAccepted.issues && Object.keys(this.state.jiraCLOSEDCRsAccepted.issues).map((issue, i) => (
this.state.jiraCLOSEDCRsAccepted.issues && this.state.jiraCLOSEDCRsAccepted.issues[i].fields && this.state.jiraCLOSEDCRsAccepted.issues[i].fields.customfield_11400 && Object.keys(this.state.jiraCLOSEDCRsAccepted.issues[i].fields.customfield_11400).map((field, customfield_11400_index) => (
fetch(`http://ca-fpscfb2:2000/ClosedCRs/add?supNumber=${this.state.jiraCLOSEDCRsAccepted.issues[i].key}&Airline=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.customfield_11400[customfield_11400_index].value}&Product=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.customfield_11600.value}&Title=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.summary}&Status=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.status.name}&DateCRRequestReceived=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.created.slice(0, 10)}&EcrNumber=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.customfield_10800}&supNumberLink=<div><a target="_blank" href="http://ksr-ca-qmaltjira.ca.kronos.com:8061/browse/${this.state.jiraCLOSEDCRsAccepted.issues[i].key}">${this.state.jiraCLOSEDCRsAccepted.issues[i].key}</a></div>`)
))
))
}
componentDidMount(){
this.addClosedCRs();
}
mysql node.js reactjs express
Whycustomfield_11600
in the fetch string ?
– bereket gebredingle
Nov 20 at 4:39
Oh its a value I am getting from the first loop to insert in my database
– bobb1213131
Nov 20 at 14:44
Any ideas why it wouldn't insert the 2nd value?
– bobb1213131
Nov 20 at 15:27
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am stuck trying to insert 2 values in an object that has 2 arrays in it. I tried looping through the 1st object, then the 2nd, but whenever I insert the data, it only inserts the value (the second loop)at index 0 instead of inserting the value at index 0,1 and so on. For example, it would only insert the value Air Canada instead of inserting Air canada and Air Canada Rouge
Here is the code and picture below to view the JSON file in order to get a better picture of my problem (the yellow highlights in my picture are the key things to look for)
Code (React)
addClosedCRs = _ => {
this.state.jiraCLOSEDCRsAccepted.issues && Object.keys(this.state.jiraCLOSEDCRsAccepted.issues).map((issue, i) => (
this.state.jiraCLOSEDCRsAccepted.issues && this.state.jiraCLOSEDCRsAccepted.issues[i].fields && this.state.jiraCLOSEDCRsAccepted.issues[i].fields.customfield_11400 && Object.keys(this.state.jiraCLOSEDCRsAccepted.issues[i].fields.customfield_11400).map((field, customfield_11400_index) => (
fetch(`http://ca-fpscfb2:2000/ClosedCRs/add?supNumber=${this.state.jiraCLOSEDCRsAccepted.issues[i].key}&Airline=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.customfield_11400[customfield_11400_index].value}&Product=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.customfield_11600.value}&Title=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.summary}&Status=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.status.name}&DateCRRequestReceived=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.created.slice(0, 10)}&EcrNumber=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.customfield_10800}&supNumberLink=<div><a target="_blank" href="http://ksr-ca-qmaltjira.ca.kronos.com:8061/browse/${this.state.jiraCLOSEDCRsAccepted.issues[i].key}">${this.state.jiraCLOSEDCRsAccepted.issues[i].key}</a></div>`)
))
))
}
componentDidMount(){
this.addClosedCRs();
}
mysql node.js reactjs express
I am stuck trying to insert 2 values in an object that has 2 arrays in it. I tried looping through the 1st object, then the 2nd, but whenever I insert the data, it only inserts the value (the second loop)at index 0 instead of inserting the value at index 0,1 and so on. For example, it would only insert the value Air Canada instead of inserting Air canada and Air Canada Rouge
Here is the code and picture below to view the JSON file in order to get a better picture of my problem (the yellow highlights in my picture are the key things to look for)
Code (React)
addClosedCRs = _ => {
this.state.jiraCLOSEDCRsAccepted.issues && Object.keys(this.state.jiraCLOSEDCRsAccepted.issues).map((issue, i) => (
this.state.jiraCLOSEDCRsAccepted.issues && this.state.jiraCLOSEDCRsAccepted.issues[i].fields && this.state.jiraCLOSEDCRsAccepted.issues[i].fields.customfield_11400 && Object.keys(this.state.jiraCLOSEDCRsAccepted.issues[i].fields.customfield_11400).map((field, customfield_11400_index) => (
fetch(`http://ca-fpscfb2:2000/ClosedCRs/add?supNumber=${this.state.jiraCLOSEDCRsAccepted.issues[i].key}&Airline=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.customfield_11400[customfield_11400_index].value}&Product=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.customfield_11600.value}&Title=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.summary}&Status=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.status.name}&DateCRRequestReceived=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.created.slice(0, 10)}&EcrNumber=${this.state.jiraCLOSEDCRsAccepted.issues[i].fields.customfield_10800}&supNumberLink=<div><a target="_blank" href="http://ksr-ca-qmaltjira.ca.kronos.com:8061/browse/${this.state.jiraCLOSEDCRsAccepted.issues[i].key}">${this.state.jiraCLOSEDCRsAccepted.issues[i].key}</a></div>`)
))
))
}
componentDidMount(){
this.addClosedCRs();
}
mysql node.js reactjs express
mysql node.js reactjs express
asked Nov 20 at 2:21
bobb1213131
668
668
Whycustomfield_11600
in the fetch string ?
– bereket gebredingle
Nov 20 at 4:39
Oh its a value I am getting from the first loop to insert in my database
– bobb1213131
Nov 20 at 14:44
Any ideas why it wouldn't insert the 2nd value?
– bobb1213131
Nov 20 at 15:27
add a comment |
Whycustomfield_11600
in the fetch string ?
– bereket gebredingle
Nov 20 at 4:39
Oh its a value I am getting from the first loop to insert in my database
– bobb1213131
Nov 20 at 14:44
Any ideas why it wouldn't insert the 2nd value?
– bobb1213131
Nov 20 at 15:27
Why
customfield_11600
in the fetch string ?– bereket gebredingle
Nov 20 at 4:39
Why
customfield_11600
in the fetch string ?– bereket gebredingle
Nov 20 at 4:39
Oh its a value I am getting from the first loop to insert in my database
– bobb1213131
Nov 20 at 14:44
Oh its a value I am getting from the first loop to insert in my database
– bobb1213131
Nov 20 at 14:44
Any ideas why it wouldn't insert the 2nd value?
– bobb1213131
Nov 20 at 15:27
Any ideas why it wouldn't insert the 2nd value?
– bobb1213131
Nov 20 at 15:27
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53385317%2f2-loops-to-insert-data-in-my-databasemysql-using-reactjsfrontend-and-nodejs%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Why
customfield_11600
in the fetch string ?– bereket gebredingle
Nov 20 at 4:39
Oh its a value I am getting from the first loop to insert in my database
– bobb1213131
Nov 20 at 14:44
Any ideas why it wouldn't insert the 2nd value?
– bobb1213131
Nov 20 at 15:27