Hi,
I have tried to extend the tree basic sample and add a breadcrumbs navigation on the top.
View:
<mvc:View
controllerName="sap.m.sample.Tree.Page"
xmlns:mvc="sap.ui.core.mvc"
xmlns="sap.m">
<Breadcrumbs id="bread" currentLocationText="{/sNode}">
</Breadcrumbs>
<Tree
id="Tree"
items="{path: '/'}"
toggleOpenState="onToggle">
<StandardTreeItem id="item" title="{title}" type="Navigation" press="test"/>
</Tree>
</mvc:View>
Controller:
var PageController = Controller.extend("sap.m.sample.Tree.Page", {
onInit : function (evt) {
var oModel = new JSONModel(jQuery.sap.getModulePath("sap.m.sample.Tree", "/Tree.json"));
var data = this.getView().setModel(oModel);
},
onToggle: function(oEvent) {
var lItem = oEvent.getParameters().itemContext.sPath;
var lItem2 = oEvent.getParameter("itemContext");
var nodes = this.getView().getModel().getProperty(lItem);
var sNode = this.getView().getModel().getProperty(lItem).title;
var oBreadCrumbs = this.byId("bread");
if(!(paths.includes(lItem))){
arr.push(sNode);
}
else{
var index = arr.indexOf(sNode);
paths.length = index+1;
arr.length = index+1;
}
paths.push(lItem);
oBreadCrumbs.removeAllLinks();
for(var i=0; i<arr.length; i++){
if(i == arr.length -1){
oBreadCrumbs.setCurrentLocationText(arr[i]);
}
else{
var link = new sap.m.Link({
text: arr[i],
press: [this.tryOne, oBreadCrumbs]
});
oBreadCrumbs.addLink(link);
}
}
},
tryOne: function(oEvent)
{
var t = oEvent.getSource();
var n = this.indexOfLink(t);
this.removeAllLinks();
this.setCurrentLocationText(arr[n]);
for(var i = 0; i<n; i++){
var li = new sap.m.Link({
text: arr[i],
press: [PageController.onToggle, PageController]
});
this.addLink(li);
}
},
In onToggle function I create the links for the breadcrumbs each time a node expand. What I want to do, is after I created the navigation, when I click a link, the links after that will be removed and the clicked link will be the current Location. So on my first time created navigation, on press I run the tryOne function. In this function, I remove and then create again all the links. My problem is what should be done when a link clicked on the second time navigation. I am trying to run again the tryOne function, but nothing seems to be happend. No errors and no results. Can anyone help?
Request clarification before answering.
| User | Count |
|---|---|
| 8 | |
| 5 | |
| 4 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.