我正在使用主/详细模板上的项目,我在Master.view.xml中创建了一个按钮,对于SAPUI5和SAP Web IDE开发我仍然是新手,当我单击该按钮时,实际上什么也没发生,甚至认为当我在chrome上调试时,没有发现错误,这是我的Master.view.xml
<sap.ui.layout:content>
<Button text="Ajouter" enabled="{appView>/addEnabled}" width="100px" id="addButton" icon="sap-icon://add" press="onAdd" activeIcon="sap-icon://accept"/>
</sap.ui.layout:content>
这是我的主控制器方法:
onAdd : function(){
this.getRouter().getTargets().display("create");
},
这是我的Component.js路由
routing: {
config: {
routerClass: com.emi.MyRouter,
viewType: "XML",
viewPath: "com.emi.view",
targetAggregation: "detailPages",
// controlId: "idAppControl",
// targetControl: "idAppControl",
controlAggregation: "detailPages",
clearTarget: false
},
routes: [
{
pattern: "",
name: "main",
view: "Master",
targetAggregation: "masterPages",
targetControl: "idAppControl",
subroutes: [
{
pattern: "{entity}/:tab:",
name: "detail",
view: "Detail"
}
, {
pattern: "{entity}/:tab:/{item}",
name: "userDetails",
view: "UserDetails"
},
{
pattern: "create",
name: "createEntity",
view: "CreateEntity",
target: "create"
}
]
},
{
name: "catchallMaster",
view: "Master",
targetAggregation: "masterPages",
targetControl: "idAppControl",
subroutes: [
{
pattern: ":all*:",
name: "catchallDetail",
view: "NotFound",
transition: "show"
}
]
}
],
targets: {
master: {
viewName: "Master",
viewLevel: 1,
viewId: "master",
controlAggregation: "masterPages"
// controlId: "idAppControl"
},
object: {
viewName: "Detail",
viewId: "detail",
viewLevel: 2
},
create: {
// viewPath: "sap.ui.com.emi.view.CreateEntity",
viewName: "CreateEntity",
targetAggregation: "pages",
viewLevel: 1,
controlAggregation: "detailPages",
transition: "show",
controlId:"idAppControl"
}
}
}
},
最后,这是我在CreateEntity.Controller.js中的oninit方法
onInit: function() {
var oRouter, oTarget;
oRouter = this.getRouter();
oTarget = oRouter.getTargets().getTarget("create");
},
但是,当我单击该按钮时,什么也没有发生,并且当我调试代码时发现没有错误,这意味着我的视图在那里但没有显示。我怀疑oninit函数中有问题,请您能帮我吗?谢谢
最佳答案
请执行以下操作:
确保onAdd事件由警报alert("reached the onAdd event");
触发,例如在onAdd事件开始时。
如果触发了onAdd事件,则应使用.getRouter().navTo("create");
命令完成导航。有关oRouter.getTargets().getTarget("create");
的正确用法,请参阅绑定演练的Step 5
最后,最好将路由配置放入您的manifest.json
中。也就是说,路由部分应仅具有以下属性:pattern
,name
和target
。在您的情况下:
pattern: "create",
name: "createEntity",
target: "create"
您还需要调整其他条目-再次参考上面链接的导航演练。
最后,您的目标部分可以非常简单地阅读如下:
"createEntity": {
"viewPath": "com.emi.view.CreateEntity",
"viewName": "CreateEntity",
"viewLevel" : 2
希望这可以帮助。强烈建议您执行以上链接的SAP提供的演练!!!