Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
278 views
in Technique[技术] by (71.8m points)

json - Use breadcrumbs with tree dynamically SAPUI

I am trying to extend the tree basic sample and adding breadcrumbs depending on the tree level.

This is my xml:

<mvc:View
controllerName="sap.m.sample.Tree.Page"
xmlns:mvc="sap.ui.core.mvc"
xmlns="sap.m">
<Breadcrumbs id="bread" currentLocationText="Start">
    <Link text="{/lItem}"/>
</Breadcrumbs>
    <Tree
        id="Tree"
        items="{path: '/'}"
        toggleOpenState="onToggle">
        <StandardTreeItem id="item" title="{text}"/>
    </Tree>

And here is my controller:

sap.ui.define(['sap/ui/core/mvc/Controller', 'sap/ui/model/json/JSONModel'],
function(Controller, JSONModel) {
"use strict";

var PageController = Controller.extend("sap.m.sample.Tree.Page", {
    onInit : function (evt) {
        // set explored app's demo model on this sample
        var oModel = new JSONModel(jQuery.sap.getModulePath("sap.m.sample.Tree", "/Tree.json"));
        this.getView().setModel(oModel);
    },

    onToggle: function(oEvent) {
        var data = this.getView().getModel().getData();
        //var lItem = this.byId("Tree").getBindingContextPath();
        var lItem = oEvent.getParameters().itemIndex;
        var oBreadCrumbs = this.byId("bread");
        oBreadCrumbs.setCurrentLocationText(lItem);
        console.log(lItem);

    }

});

return PageController;

});

The tree.json is a simple json with nodes, like this . The breadcrumbs controls, doesn't create the levels and each time I expand a node it rewrites the last level. Any ideas? Thank you

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I finally figure it out, doing this:

View file:

<mvc:View
controllerName="sap.m.sample.Tree.Page"
xmlns:mvc="sap.ui.core.mvc"
xmlns="sap.m">
<Breadcrumbs id="bread" currentLocationText="{/sNode}">
    <!-- <Link id="link" text="paly"/> -->
</Breadcrumbs>
    <Tree
        id="Tree"
        items="{path: '/'}"
        toggleOpenState="onToggle">
        <StandardTreeItem id="item" title="{title}"/>
    </Tree>

Controller:

onToggle: function(oEvent) {

        var lItem = oEvent.getParameters().itemContext.sPath;
        var sNode = this.getView().getModel().getProperty(lItem).title;
        var oBreadCrumbs = this.byId("bread");

        arr.push(sNode);

        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.generateLinks, sNode
                });
                oBreadCrumbs.addLink(link);
            }

        }

    },

    generateLinks : function(sNode)
    {   
        console.log(sNode);
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...