This question has been flagged
2 Replies
7482 Views

Hello,

I'm trying to display records using QWeb. I have a simple structure : Client(id, name)

I want to have a view displaying

id - name
0 - smith
1 - john
2 - jack
3 - bob

So I have made a QWeb code :

<templates>
<t t-name="MyView">
    <table>
        <thead>
            <tr>
                <th t-foreach="fields_view" t-as="field">
                    <t t-esc="fields[field.attrs.name].string" />
                </th>
            </tr>
        </thead>
        <tbody>
        </tbody>
    </table>
</t>
</templates>

This code should just show the header line, but it doesn't. I get an error : "No enumerator given to foreach"

How to make the simple view I want to make with QWeb ? I'm using OE6.1

Thank You

Avatar
Discard

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

Hi, I'm facing the same problem as described on the top, but your solution doesnt work for me. Please help. this is my xml:

Hello
openerp.oepetstore = function(instance, local) { var _t = instance.web._t, _lt = instance.web._lt; var QWeb = instance.web.qweb; // standard widget for our page local.HomePage = instance.Widget.extend({ className: 'oe_petstore_homepage', template: "HomePageTemplate", // load template from xml (possibility no 1 - standard) init: function(parent) { this._super(parent); this.name = "Mordecai"; this.votes = []; }, start: function() { this._super(); this.votes = ["test", "test"]; //this.get('value'); }, }); // registers our basic widget as a client action instance.web.client_actions.add('petstore.homepage', 'instance.oepetstore.HomePage'); }
Best Answer

Hi, I'm facing the same problem as described on the top, but your solution doesnt work for me. Please help. this is my xml:

 

<code>

openerp.oepetstore = function(instance, local) {
    var _t = instance.web._t,
        _lt = instance.web._lt;
    var QWeb = instance.web.qweb;

    // standard widget for our page
    local.HomePage = instance.Widget.extend({
        className: 'oe_petstore_homepage',
        template: "HomePageTemplate",                                    // load template from xml (possibility no 1 - standard)
        
        init: function(parent) {
            this._super(parent);
            this.name = "Mordecai";
            this.votes = [];
        },
        
        start: function() {
            this._super();
            this.votes = ["test", "test"]; //this.get('value');
        },
    });
        
    // registers our basic widget as a client action
    instance.web.client_actions.add('petstore.homepage', 'instance.oepetstore.HomePage');    
}

</code>

 

Avatar
Discard