开发者

Dojo Widget need event when everything is "ready"

开发者 https://www.devze.com 2022-12-27 23:30 出处:网络
i have an custom widget in dojo. My Problem is to check some kind of access rules wich are passed to the widget.

i have an custom widget in dojo. My Problem is to check some kind of access rules wich are passed to the widget.

if check the rules after the widget is fully loaded everything works fine. But i have to remove some text and buttons before it is displayed.

I've tryted the startup, and postcreate hook (-: is there something l开发者_如何学运维ike "aftercreate" ?


The first solution I can think of is to begin with hiding the restricted elements and then remove them.

In css:

.hidden{ display: none }

In widget's template for all permissions-sensitive elements:

<div class="${permissionsSensitiveElementsClass}">...</div>

In widget's code:

permissionsSensitiveElementsClass: "",
postMixInProperties: function(){
  if(!this.hasPermissions()){
    this.permissionsSensitiveElementsClass = "hidden";
  }
  this.inherited(arguments);
},
startup: function(){
  // remove elements if necessary
},
hasPermissions: function(){
  // permissions check
},


The final rendering function would be startup(). For widgets which are initially hidden, startup gets called automatically when call is made to show(). dijit.layout.Container has 'addChild(widget)' functionality, which will fire widget.startup() when a/multiple child(ren) are added.

You would benifit from: http://dojotoolkit.org/documentation/tutorials/1.6/understanding_widget/

Widget lifecycle:

([widget].constructor());
[widget].postscript();
[widget].create();
[widget].postMixinProperties();
[widget].buildRendering();
[widget].postCreate();  // this is the most important one!
[widget].startup();

The true answer to your question lies here;

dojo.declare("mydijit", ["dijit/_Widget"], {

  startup: function() {
    // call superclass functionality before applying hide on specific elements
    this.inherited(arguments);

    if(foo) dojo.destroy(this.fooNode);
    if(bar) dojo.destroy(this.barNode);
  },
  onShow: function() {
    if(foo.changed || bar.changed) {
        // act upon it
    }
  }

}
0

精彩评论

暂无评论...
验证码 换一张
取 消