How to dynamically load an XML fragment in XML view?

前端 未结 2 1913
有刺的猬
有刺的猬 2021-01-05 17:04

Suppose I have the following XML view:


    
        &l         


        
相关标签:
2条回答
  • 2021-01-05 17:12

    I think the only solution will be initialization of fragment from onInit method of controller:

    sap.ui.controller("my.controller", {
        onInit : function(){
            var oLayout = this.getView().byId('mainLayout'), //don't forget to set id for a VerticalLayout
                oFragment = sap.ui.xmlfragment(this.fragmentName.bind(this));
            oLayout.addContent(oFragment);
        },
    
        fragmentName : function(){
           return "my.fragment";
        }
    });
    
    0 讨论(0)
  • 2021-01-05 17:19

    The fragment name can also result from a binding, including an expression binding which evaluates to a constant. As formatter functions return strings, and not booleans, === 'true' has been added in the following example:

    Example: Dynamic Fragment Name

    <core:Fragment fragmentName="{= ${path: 'facet>Target', formatter: 'sap.ui.model.odata.AnnotationHelper.isMultiple'} === 'true'
        ? 'sap.ui.core.sample.ViewTemplate.scenario.TableFacet'
        : 'sap.ui.core.sample.ViewTemplate.scenario.FormFacet' }" type="XML"/>
    
    0 讨论(0)
提交回复
热议问题