在 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]; },
},
....
....
]
在我的 costum 模块中,我只想在列表的末尾添加一个元素,我设法添加了它:
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
],
}
现在我的问题是如何将我的元素添加到旧列表中而不必重复孔列表。
我们可以访问 initialize 方法中的所有属性的好处:
// 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;
},
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句