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
566 views
in Technique[技术] by (71.8m points)

sapui5 - Using HTML fragments with declarative HTML views

I am trying to decompose a large HTML view down into smaller, more manageable chunks.

Is it possible to use fragments to do this?

For example, I have a fragment file (view.configurator.Summary.fragment.html) containing the following:

<div data-sap-ui-type="sap.m.Button" data-text="Hello"></div>

In my parent file, I try to include the fragment as follows:

            <div data-sap-ui-type="sap.m.VBox" class="summary-panel-content">

                <div data-sap-ui-type="sap.ui.core.Fragment"
                     data-fragment-name="view.configurator.Summary" 
                     data-type="HTML"></div>

            </div>

However I get the following Error in the console:

Please provide a fragment name

Any ideas?

Seems like its a bug, but you can workaround by wrapping the fragment in a custom control

 sap.ui.core.Control.extend("sap.mic.controls.Fragment", {

    metadata: {
        properties: {
            "name": "string"
        }
    },

    init: function () {
    },

    renderer: function (renderManager, control) {
        var fragmentName = control.getProperty("name"),
            fragment = sap.ui.htmlfragment(fragmentName);

        renderManager.renderControl(fragment);
    }
});

And used like so:

<div data-sap-ui-type="sap.m.Page" data-enable-scrolling="false">

    <div data-sap-ui-type="sap.mic.controls.Fragment"
         data-name="view.configurator.Summary"></div>

</div>
See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

In XML-View

Include the view with this:

<mvc:XMLView viewName="your.namespace.ViewName" async="true" />

Whereas xmlns:mvc="sap.ui.core.mvc"

In HTML-View

You can include Views like this:

<div data-sap-ui-type="sap.ui.core.mvc.HTMLView" data-view-name="your.namespace.ViewName" data-async="true"></div>

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

...