添加另一个元素到模型列表 [odoo-8] pos javascript
add another element to models list [odoo-8] pos javascript
在 pos javascript 中有这段代码:
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]; },
},
....
....
]
在我的服装模块中,我只想将一个元素添加到列表的末尾,
我设法添加它这样做:
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
],
}
现在我的问题是如何将我的元素添加到旧列表而不必重复空列表。
好在我们可以在初始化方法中访问所有属性:
// 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;
},
});
在 pos javascript 中有这段代码:
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]; },
},
....
....
]
在我的服装模块中,我只想将一个元素添加到列表的末尾, 我设法添加它这样做:
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
],
}
现在我的问题是如何将我的元素添加到旧列表而不必重复空列表。
好在我们可以在初始化方法中访问所有属性:
// 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;
},
});