{{/for}} here " /> {{/for}} here " /> {{/for}} here "/>

Jsrender data value break on whitespace

65 views Asked by At

i am using jsrender and i got issue on accessing value

{{for items}}
  <input type="text" id="id1" value="{{*: Json.stringify(data)}}" />
{{/for}}

here i got value as: "{" id":"1","name":"johnny depp"}"

$("#id1").val() gives '{' all other values trimmed and

<input type="text" id="id1" value={{*: Json.stringify(data)}} />

here i get: "{id":"1","name":"johnny" depp"}

$("#id1").val() gives '{id":"1","name":"johnny'

the words after the space is getting trimmed how can i show full value

i have tried the solution as in <input value={{:abc}} /> does not seem to work properly in jsviews if the value of 'abc' has whitespace but still not working

1

There are 1 answers

0
BorisMoore On BEST ANSWER

Since the string returned from stringify() includes double quotes ", you need to instead use single quotes ' for the value='...' on the markup for the input:

<input type="text" id="id1" value='{{*: JSON.stringify(data)}}' />

which will give

<input type="text" id="id1" value='{"id":"1","name":"johnny depp"}' />

Now $("#id1").val() will give: '{"id":"1","name":"johnny depp"}'