This question has been flagged
1 Reply
16089 Views

JS Code :

var context = {
    "title": "Random Title",
    "items": [
        { "name": "foo", "tags": {"bar": "baz", "qux": "quux"} },
        { "name": "Lorem", "tags": { "ipsum": "dolor" }
        }
    ]
}
self.$el.html(QWeb.render( self.template,  context ));

Template:

<templates>
  <div t-name="example_template" t-attf-class="base #{cls}">
    <h4 t-if="title"><t t-esc="title"/></h4>
    <ul>
      <li t-foreach="items" t-as="item">
           <t t-esc="item.name" />
      </li>
    </ul>
  </div>
</templates>

Error Message:

 "No enumerator given to foreach"

It works fine without 't-foreach'. Thanks.

Avatar
Discard

I had the same problem but now i've solve it. I share my code hoping that it will be helpfull (sorry for my poor english) : <ol> <li t-foreach="widget.categories" t-as="category"> <img class="oe_hr_responsive_category" t-att-src="widget.get_image_url(category)" /> </li> </ol>

I have the same error. Since there is many people asking this question I suspect a bug, here is the bug report : https://bugs.launchpad.net/openobject-addons/+bug/1301474

Best Answer

Please look at my bug ticket on Launchpad : https:// bugs.launchpad.net/openobject-addons/+bug/1301474?comments=all (It was finally not a bug).

You need to initialize the variable in _init, otherwise the foreach will not find it. Exemple :

init: function (field_manager, node) {
    this._super(field_manager, node);
    this.votes = [];
},

start: function() {
    this._super();
    this.votes = ["test", "test"]; //this.get('value');
},
Avatar
Discard