2

Am trying to assign payment_term value to the state.payment_terms using JSON.stringify(). But its giving value with in double quotes in the dropdown component. How to avoid the extra double quotes.

Please find my code below.

<select name="payment_terms" value={ this.state.payment_terms != undefined ? 
 this.state.payment_terms : 
 this.state.payment_terms=JSON.stringify(payment_term) }  >
{payment_terms}
</select>

Am populating payment_term with the below code.

if(this.state.Payment_Term != null)
    {
        var payment_terms = [];
        var payment_term;
        for( var i=0; i<this.props.Payment_Term.length; i++)
        {
            if( this.state.Payment_Term[i].Payment_Detail != null )
                {
                    payment_terms.push(  <option value=
                    {this.state.Payment_Term[i].Payment_Detail}>
                    {this.state.Payment_Term[i].Payment_Detail}</option>  )
                }
            payment_term = this.state.Payment_Term[0].Payment_Detail;
        }

    }

Please find the attached payment details structure

7
  • Why are you using JSON.stringify? Commented Jan 1, 2018 at 12:53
  • Otherwise, its coming [object,object]. So that i tried with JSON.stringify. Commented Jan 1, 2018 at 12:55
  • It would be helpful to see the structure of the PaymentTerm object, specifically PaymentTerm.Payment_Detail. Commented Jan 1, 2018 at 12:57
  • Payment Details structure has been attached. Commented Jan 1, 2018 at 13:02
  • @Karthikeyan why do you need to use JSON.stringify ? Would it fail if you removed it? Commented Jan 1, 2018 at 13:04

2 Answers 2

2

Try doing this: JSON.parse(JSON.stringify(payment_terms))

I guess this must fix your problem in double quotes.

Sign up to request clarification or add additional context in comments.

Comments

-1

You could just replace all quotes with an empty string:

this.state.payment_term = this.state.payment_term.replace(/\"/g, "");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.