2

I'm using jsviews to render the following template

recoList = [{title:"Apple"},{title:"Two Apples"}];

<script id="sampleTmpl" type="text/x-jsrender">
{{for recoList}}
  <input type="text" value={{:title}} />
{{/for}}
</script>

Whenever the value of title has a whitespace in it, like "Two Apples", then input box is rendered as

<input type="text" value="Two" />

The word after the whitespace is simply spliced off!

How can i give the full string to the value?

BorisMoore
  • 8,444
  • 1
  • 16
  • 27
S.Raaj Nishanth
  • 242
  • 2
  • 15

2 Answers2

1

Adding a data-link instead of value={{:title}} solves the problem for now.

Like so :

<input type="text" data-link="title" />

However, i still don't know why value={{:title}} splices the string after whitespace.

S.Raaj Nishanth
  • 242
  • 2
  • 15
1

The reason is simple. You are missing the quotes:

<input type="text" value={{:title}} />

should be:

<input type="text" value="{{:title}}" />

JsRender simply replaces the tag by the value, so:

<input type="text" value=Two Apples />

should be:

<input type="text" value="Two Apples" />

You says quotes don't work, but the above should certainly work. Using data-link="title" will add the quotes, but also adds data binding, so you get two-way binding to the title field...

BorisMoore
  • 8,444
  • 1
  • 16
  • 27