简体   繁体   English

Sapui5 CustomTreeItem如何将项添加到树结构中

[英]Sapui5 CustomTreeItem How can i add an item to the tree Structure

Im facing an issue in CustomTreeItem . 我在CustomTreeItem中面临一个问题。 Im able to display the tree structure from JSON Successfully. 我能够成功地从JSON显示树结构。 But im facing an issue to add the Data manually on Click of Add Button. 但我面临一个问题,即单击添加按钮手动添加数据。

在此输入图像描述

If you see the above image if i hit on + Button i need to add one Tile in the below. 如果你看到上面的图像,如果我点击+按钮我需要在下面添加一个平铺。 But im able not able to add and im not seeing any error in the console too.. Below is my code... 但我无法添加,我也没有在控制台中看到任何错误..下面是我的代码...

XML ====` XML ====`

<Tree items="{selModel>/}" id="Tree" class="sapUiTinyMarginTop tilesClass selTree">
                                    <CustomTreeItem id="treeItem" detailPress="pressCustomTreeItem">
                                        <VBox class="customSelTile" id="customSelTile">
                                            <HBox>
                                                <VBox class="sapUiTinyMarginTop customTxts">
                                                    <Label class="sapUiSmallMarginBegin headTxtFont" text="{selModel>text}"/>
                                                    <Label class="sapUiSmallMarginBegin subHeadTxtFont" text="{selModel>subheader}"/>
                                                </VBox>
                                                <Button class="sapUiSmallMarginBegin sapUiTinyMarginTop" press="addTile" icon="sap-icon://add"/>
                                                <Button class="sapUiTinyMarginBegin sapUiTinyMarginTop" press="removeTile" icon="sap-icon://less"/>
                                            </HBox>
                                        </VBox>
                                    </CustomTreeItem>
                                </Tree>

` `

Controller :: 控制器::

var selOrgJson = [{
            "text": "Department",
            "subheader": "Production Management JP",
            "personName":"Kuwahara Atushi",
            "nodes": [{
                "text": "Department",
                "subheader": "Production JP",
                "personName":"Kawasaki Takeshi"
            }, {
                "text": "Department",
                "subheader": "Planning Scheduling JP",
                "personName":"Fukuyama Sumire",
                "nodes": [{
                    "text": "Department",
                    "subheader": "Planning Operations",
                    "personName":"Sakata Junko"
                }]
            }, {
                "text": "Department",
                "subheader": "Sales Office, North East Japan",
                "personName":"Emoto Hloronori"
            }, {
                "text": "Department",
                "subheader": "Sales Office, South East Japan",
                "personName":"Suzuki Aya"
            }, {
                "text": "Department",
                "subheader": "Partner Sales JP",
                "personName":"Kuwahara Atushi"
            }]
        }];

        var selModel = new sap.ui.model.json.JSONModel();
        selModel.setData(selOrgJson);
        this.getView().setModel(selModel, "selModel");

addTile: function (oEvt) {
        var vBox = new sap.m.VBox();
        vBox.addStyleClass("customSelTile");
        var hBox = new sap.m.HBox();
        var insideVBox = new sap.m.VBox();
        insideVBox.addStyleClass("sapUiTinyMarginTop customTxts");
        var headInput = new sap.m.Input({
            type: "Text"
        });
        var subInput = new sap.m.Input({
            type: "Text"
        });
        insideVBox.addItem(headInput);
        insideVBox.addItem(subInput);
        hBox.addItem(insideVBox);
        vBox.addItem(hBox);
        var button1 = new sap.m.Button({
            press: this.addTile,
            icon: "sap-icon://add"
        });
        var button2 = new sap.m.Button({
            press: this.removeTile,
            icon: "sap-icon://less"
        });
        hBox.addItem(button1);
        hBox.addItem(button2);
        vBox.addItem(hBox);

    },

Can some one please help how can i add a tile on Click of Add button to the CustomTreeItem . 有人可以帮助我如何添加一个瓷砖点击添加按钮到CustomTreeItem If my above approach is wrong in controller means then Please help me with some alternate solution . 如果我的上述方法在控制器方式错误,那么请帮助我一些替代解决方案。

Thank you in advance.. 先感谢您..

Fixed the issue with below piece of code.. 修复了以下代码的问题..

addTile: function (oEvt) {

        var _oItem = oEvt.getSource().getParent().getParent().getParent();
        var _sBindingPath = _oItem.getBindingContextPath();
        var _oModel = this.getView().getModel("selModel");
        var aData = _oModel.getProperty(_sBindingPath);
        var _oChildNodes = [];
        if (aData.nodes !== undefined) {
            _oChildNodes = aData.nodes;
        } else {
            aData.nodes = _oChildNodes;
        }

        var newData = {
            "text": "",
            "subheader": ""
       }

Thank you 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM