如何在sapui5中重新加载特定控件?

时间:2014-07-02 10:29:26

标签: sapui5

我在sapui5中使用视图转发器控件。我必须在按钮点击事件中仅重新加载视图转发器控件。

2 个答案:

答案 0 :(得分:4)

sap.ui.getCore().byId("ViewRepeater_Id").getModel().refresh(true);

在按钮按下事件中使用此行。

答案 1 :(得分:-1)

       var oMatrix = new sap.ui.commons.layout.MatrixLayout({
        visible : true,
        layoutFixed : true,

        columns : 3,

    });

    lblLastName = new sap.ui.commons.Label({

        text : 'LastName'

    });

    txtLastName = new sap.ui.commons.TextField({
        id : "LastName",
        editable : true

    });
    lblLastName.setLabelFor(txtLastName);

    oMatrix.createRow(lblLastName, txtLastName);
    lblName = new sap.ui.commons.Label({

        text : 'Name'

    });

    txtName = new sap.ui.commons.TextField({
        id : "name",
        editable : true

    });
    lblName.setLabelFor(txtName);

    oMatrix.createRow(lblName, txtName);

    lblCountry = new sap.ui.commons.Label({

        text : 'country'

    });

    txtCountry = new sap.ui.commons.TextField({
        id : "country",
        editable : true

    });
    lblCountry.setLabelFor(txtCountry);

    oMatrix.createRow(lblCountry, txtCountry);

    lblUrl = new sap.ui.commons.Label({

        text : 'Url'
    });

    txtUrl = new sap.ui.commons.TextField({
        id : "url",
        editable : true,

    });

    lblUrl.setLabelFor(txtUrl);

    oMatrix.createRow(lblUrl, txtUrl);
    lblSrc = new sap.ui.commons.Label({

        text : ' Image Src'
    });

    txtSrc = new sap.ui.commons.TextField({
        id : "src",
        editable : true,

    });

    lblSrc.setLabelFor(txtSrc);

    oMatrix.createRow(lblSrc, txtSrc);
    btnSave = new sap.ui.commons.Button({

        text : 'save',
        press : function() {
            saveDetails();
        }
    });
    btnCancel = new sap.ui.commons.Button({

        text : 'Cancel',
        press : function() {
            closeDialog();
        }
    });
    oCell1 = new sap.ui.commons.layout.MatrixLayoutCell({

    });
    oCell1.addContent(btnSave);

    oCell1.addContent(btnCancel);

    oMatrix.createRow("", "", oCell1);
    var oDialog1 = new sap.ui.commons.Dialog({

    });
    function openDialog() {

        oDialog1.setTitle("Update");

        oDialog1.addContent(oMatrix);

        oDialog1.open();

    }
    function closeDialog() {
        oDialog1.close();
    }

    // ////// TEMPLATE SECTION
    // //////////////////////////////////////////////////////////////////
    //
    // create the template to be used for ViewRepeater items
    var oRowTemplate_NoViews = new sap.ui.commons.layout.HorizontalLayout(
            "rowTemplateNoViews");
    oRowTemplate_NoViews.addStyleClass("rowTemplateNoViews");

    var control;
    // image
    control = new sap.ui.commons.Image();
    control.setHeight("60px");
    control.setWidth("50px");
    control.bindProperty("src", "src");
    oRowTemplate_NoViews.addContent(control);

    // text fields
    var oTextSectionLayout = new sap.ui.commons.layout.VerticalLayout(
            "textSection");
    oTextSectionLayout.addStyleClass("rowTemplateNoViewsTextSection");
    oRowTemplate_NoViews.addContent(oTextSectionLayout);

    // name field
    control = new sap.ui.commons.TextView({
        editable : true
    });
    control.bindProperty("text", {
        parts : [ {
            path : "name",
            type : new sap.ui.model.type.String()
        }, {
            path : "lastName",
            type : new sap.ui.model.type.String()
        } ],
        formatter : function(name, lastName) { // all
            // parameters
            // are
            // strings
            name = name || "";
            lastName = lastName || "";
            return name + " " + lastName;
        }
    });
    oTextSectionLayout.addContent(control);

    // country field
    control = new sap.ui.commons.TextView();
    control.bindProperty("text", "country");
    oTextSectionLayout.addContent(control);

    // link field
    control = new sap.ui.commons.Link();
    control.bindProperty("text", "href");
    oTextSectionLayout.addContent(control);
    // button field

    var control1 = new sap.ui.commons.Button({

        press : function(oEvent) {

            var name = oEvent.getSource().getParent().getBindingContext()
                    .getProperty("lastName");
            var name1 = oEvent.getSource().getParent().getBindingContext()
                    .getProperty("name");
            var country = oEvent.getSource().getParent()
                    .getBindingContext().getProperty("country");
            var url = oEvent.getSource().getParent().getBindingContext()
                    .getProperty("href");
            var src = oEvent.getSource().getParent().getBindingContext()
                    .getProperty("src");
            sap.ui.getCore().byId("LastName").setValue(name);
            sap.ui.getCore().byId("name").setValue(name1);
            sap.ui.getCore().byId("country").setValue(country);
            sap.ui.getCore().byId("url").setValue(url);
            sap.ui.getCore().byId("src").setValue(src);
            openDialog();

        }
    });

    control1.bindProperty("text", "Button");

    var control2 = new sap.ui.commons.Button({

        press : function(oEvent) {



        }
    });

    control2.bindProperty("text", "Button2");
    oTextSectionLayout.addContent(control2);

    var oLayout = new sap.ui.layout.HorizontalLayout("Layout1", {
        content : [ control1, control2 ]
    });
    oTextSectionLayout.addContent(oLayout);
    //
    // ////// End of TEMPLATE SECTION
    // ///////////////////////////////////////////////////////////

    // ////// CONTROL SECTION
    // ///////////////////////////////////////////////////////////////////
    //
    // create view repeater title (optional)
    var oTitle_NoViews = new sap.ui.commons.Title({
        text : "REPEATER with default view",
        level : sap.ui.commons.TitleLevel.H1
    });
    var btnAddNew = new sap.ui.commons.Button({
        text : "Add New",
        press : function() {

            openDialog();
        }

    });
    btnAddNew.placeAt("content");

    // create the row repeater control

    var oViewRepeater_NoViews = new sap.suite.ui.commons.ViewRepeater(
            "view_repeater", {
                title : oTitle_NoViews,

                noData : new sap.ui.commons.TextView({
                    text : "Sorry, no data available!"
                }),

                showViews : false, // disable view selector
                showSearchField : false,
                showMoreSteps : 10, // you can use 'Show
                // More' feature
                // instead of paging

                // set view properties directly to the
                // repeater
                responsive : true,
                itemMinWidth : 210,
                numberOfRows : 12, // view property
                // NumberOfTiles has
                // legacy name here
                rows : {
                    path : "/data",
                    template : oRowTemplate_NoViews
                }
            });
    oViewRepeater_NoViews.addStyleClass("vrNoViews");
    oViewRepeater_NoViews.placeAt("content");

    //
    // ////// End of CONTROL SECTION
    // ////////////////////////////////////////////////////////////

    // create test data
    var dataObject = {
        data : [ {
            lastName : "Platte",
            name : "Rudolf",
            href : "http://www.sap.com",
            Button : "edit",
            Button2 : "delete",
            src : "viewrepeater/images/persons/male_PlatteR.jpg",
            availableVacation : Math.floor(Math.random() * 28),
            gender : "male",
            country : "US"
        }, {
            lastName : "Dwyer",
            name : "Nora",
            href : "http://www.sap.com",
            Button : "edit",
            Button2 : "delete",
            src : "viewrepeater/images/persons/female_DwyerN.jpg",
            availableVacation : Math.floor(Math.random() * 28),
            gender : "female",
            country : "US"
        }
        ]
    };

    function saveDetails(oEvent) {
        item = {};
        var lastName = sap.ui.getCore().byId("LastName").getValue();
        var name = sap.ui.getCore().byId("name").getValue();
        var country = sap.ui.getCore().byId("country").getValue();
        var url = sap.ui.getCore().byId("url").getValue();
        var src = sap.ui.getCore().byId("src").getValue();

        item["lastName"] = lastName;
        item["name"] = name;
        item["country"] = country;
        item["url"] = url;
        item["src"] = src;

        dataObject.data.push(item);

        sap.ui.getCore().byId("LastName").setValue("");
        sap.ui.getCore().byId("name").setValue("");
        sap.ui.getCore().byId("country").setValue("");
        sap.ui.getCore().byId("url").setValue("");
        sap.ui.getCore().byId("src").setValue("");

    }

    // create JSON model
    var oModel = new sap.ui.model.json.JSONModel();
    oModel.setData(dataObject);
    sap.ui.getCore().setModel(oModel);