1

I added a combobox in a list-table template

<script type="text/x-handlebars-template" id="listItemTmpl">
    <tr>                             
        <td>{{partNo}}</td>
        <td>
             <select name="selectCombo" id="selectCombo">
                    {{#each chks}}
                    <option value='{{this.id}}' {{#if(this.id==status)}}selected{{/if}}>{{this.name}}</option>
                    {{/each}}
                </select>
        </td>
    </tr>

</script>

so my chk model is;

chkModel = Backbone.Model.extend({
   urlRoot:url,
   defaults:{
        name:""
   }

});

But now I get a error like this;

Uncaught Error: Parse error on line 13:
...ue='{{this.id}}' {{#if(this.id==status)}
-----------------------^
Expecting 'ID', got 'undefined' 

so what can I do?

Cœur
  • 37,241
  • 25
  • 195
  • 267
fa.
  • 63
  • 2
  • 11

1 Answers1

0

So it seems you want to populate the select box with a bunch of depending on the model attributes. Handlebar.js seems to support looping so try the following. Note that I think you have an incorrect structure with Models and Collections. From what I understand you have a model and one of its attributes is a collection. Check the backbone documentation to see how to get and set attributes. Use the proper method, otherwise events will not get triggered.

I was going to try and post some code but I fear I will get it wrong since I don't understand the context and everything you are doing.

Take a bit of time and go through this tutorial to better understand how you should be doing things.

http://coenraets.org/blog/2011/12/backbone-js-wine-cellar-tutorial-part-1-getting-started/

Comment if you need help after reading the blog


To add to this. The below code is a handlebar.js sample that can loop through JSON items (in your case they will be model attributes)

{{#if items}}
 <ul>
    {{#each items}}
      <li>
        {{this.name}}
      </li>
    {{/each}}
  </ul>
{{/if}}
dbJones
  • 762
  • 1
  • 10
  • 31
Xerri
  • 4,916
  • 6
  • 45
  • 54
  • Firstly thank u for answering, yes ı want to render combobox depending on the data in my model, but ım using handlebar.js for templates,so can u explain a little more please? – fa. Dec 07 '12 at 07:35
  • Ok I just had a look at your code again to understand it.....let me edit the answer above – Xerri Dec 07 '12 at 09:10
  • ı also edit,if u have time, can u check it again, and thank u so much. – fa. Dec 07 '12 at 11:19
  • I think you can remove the 'this.' in the templates and use 'id' and 'name'. Try that – Xerri Dec 07 '12 at 13:45