PermissionsBehaviour =
{
ready: function ()
{
var _th = this;
this._getRoles().then(function (d)
{
_th.set('perms_roles', d);
});
},
properties:
{
perms_roles: { type: Array, value: [] },
},
_getRoles: function ()
{
return $.get(Global.Settings.RootWebUrl +
"Permission/GetUserRoles", function (result) { });
}
}
答案 0 :(得分:1)
您可以在聚合物3中将其定义为mixin:https://polymer-library.polymer-project.org/3.0/docs/devguide/custom-elements#defining-mixins
import {dedupingMixin} from '@polymer/polymer/lib/utils/mixin.js';
let internalMyMixin = function(superClass) {
return class extends superClass {
constructor() {
super();
this.addEventListener('keypress', (e) => this._handlePress(e));
}
static get properties() {
return {
bar: {
type: Object
}
};
}
static get observers() {
return [ '_barChanged(bar.*)' ];
}
_barChanged(bar) { ... }
_handlePress(e) { console.log('key pressed: ' + e.charCode); }
}
}
const MyMixin = dedupingMixin(internalMyMixin);
export {MyMixin as default};
然后按如下所示使用mixin:
import {MyMixin} from './my-mixin.js';
class Foo extends MyMixin(PolymerElement) { ... }