dojo如何动态更改tabContainer中选项卡的标题?
如果我通过dojo进入了tab 麦可德dojo如何动态更改tabContainer中选项卡的标题?,dojo,Dojo,如果我通过dojo进入了tab 麦可德 var tab=new dijit.layout.ContentPane({ title:formCount, id:''+formCount, content:cont, class:'tab', closable: true, onClose:function(){ return confirm('Relly want to remo
var tab=new dijit.layout.ContentPane({
title:formCount,
id:''+formCount,
content:cont,
class:'tab',
closable: true,
onClose:function(){
return confirm('Relly want to remove?');
}
});
dijit.byId('tabContainer').addChild(tab);
创建选项卡后,我希望通过dijit/Dialog动态更改选项卡标题。
但我不知道应该如何实现,请告诉我实现这一点的最佳方法是创建自己的小部件并从dijit/layout/ContentPane扩展,例如:
declare([ContentPane]{
});
然后可以添加内容以显示对话框,例如:
declare([ContentPane]{
btn:domConstruct.create(“按钮”{
innerHTML:“更改标题”,
}),
_createButton:function(){
domConstruct.place(this.btn,this.domNode);
在(this.btn,“click”,lang.hitch(this,this.\u showDialog))上;
},
后创建:函数(){
这是继承的(论点);
这是;
这个;
}
});
postreate
函数是Dojo中小部件生命周期的一部分,在加载小部件时自动执行。因此,我们使用它向contentpane添加一个“更改标题”按钮,单击该按钮时调用函数this.\u showDialog()
(这是您在this.\u createButton()
中可以看到的)
当然,在实际显示之前,您还需要创建一个dijit/Dialog,这样您就可以执行以下操作:
declare([ContentPane]{
/** ... */
对话框:空,
editField:null,
okBtn:null,
_showDialog:function(){
this.editField.value=this.title;
this.dialog.show();
},
_createDialog:function(){
var div=domConstruct.create(“div”);
domConstruct.place(div,this.domNode);
this.dialog=新建对话框({
标题:“更改标题”,
内容:“”
},分区);
this.editField=domConstruct.create(“输入”{
键入:“文本”
});
this.okBtn=domConstruct.create(“按钮”{
innerHTML:“OK”
});
放置(this.editField、this.dialog.containerNode);
domConstruct.place(this.okBtn、this.dialog.containerNode);
在(this.okBtn,“click”,lang.hitch(this,this._saveTitle))上;
},
/** .. */
});
这里发生的事情是,我们创建了一个带有简单文本字段和按钮(OK按钮)的对话框,所有这些都可以在中找到
在this.\u showDialog()
中,您可以看到我首先将文本字段的值更改为contentpane的标题。然后我显示我们之前创建的对话框
现在,当按下OK(确定)按钮时,您只需读取该值:
declare([ContentPane]{
/** ... */
_saveTitle:function(){
this.set(“title”,this.editField.value);
this.dialog.hide();
},
/** ... */
});
这就是你真正需要的。您可以在JSFIDLE上找到一个工作示例:非常感谢您提供了详细的答案^^