在模型列表中添加另一个元素[odoo-8] pos javascript [英] add another element to models list [odoo-8] pos javascript

查看:84
本文介绍了在模型列表中添加另一个元素[odoo-8] pos javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在pos javascript中有以下代码:

in pos javascript there this code:

   module.PosModel = Backbone.Model.extend({
       .....
       .....
      models: [
            {
                model:  'res.users',
                fields: ['name','company_id'],
                ids:    function(self){ return [self.session.uid]; },
                loaded: function(self,users){ self.user = users[0]; },
            },
             ....
             ....
          ]

在我的costum模块中,我只想在列表末尾添加一个元素, 我设法添加它:

In my costum module i just want to add one element to the end of the list, I managed to add it doing this:

           module.PosModel = module.PosModel.extend({
               models: [
                    {
                        model:  'res.users',
                        fields: ['name','company_id'],
                        ids:    function(self){
                        return [self.session.uid];
                         },
                        loaded: function(self,users){ self.user = users[0]; },
                    },
                    .....
                    // repeate the same list with my new element 
                  ],
               }

现在我的问题是如何将我的元素添加到旧列表中,而不必重复孔列表.

Now my question is how to just add my element to the old list without having to repeate the hole list.

推荐答案

在初始化方法中,我们可以访问所有属性的好处是

The good thing that we have access to all attribute in initialize method:

    // in needed to save prototype here
    // so it will not cause a recursive loop
    var _super = module.PosModel.prototype;
    module.PosModel = module.PosModel.extend({
     initialize: function (session, attributes) {
        // call super to set all properties
        _super.initialize.apply(this, arguments);
        // here i can access the models list like this and add an element.
        this.models.push({
        // load allowed users
            model:  'res.users',
            fields: ['name'],
            domain: function(self){ return [['id','in',self.config.user_ids]]; },
            loaded: function(self,users){
                console.log(users);
                self.allowed_users = users;
            },
        })
        return this;
     },

    });

这篇关于在模型列表中添加另一个元素[odoo-8] pos javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆