javascript - SAPUI5 片段无法打开

标签 javascript html fragment sapui5

我正在尝试在 SAPUI5 中制作一个弹出窗口/片段,显示数据库中列出的注释。我知道数据库与调用一起工作得很好。当我单击应该打开片段的按钮时,没有任何反应。

Controller .js

_getDialog: function() {
        // associate controller with the fragment
        this.oCommentDialog = sap.ui.xmlfragment("really.long.destination.fragment.CommentDialog", this);
        this.getView().addDependent(this.oCommentDialog);

        // toggle compact style
        jQuery.sap.syncStyleClass("sapUiSizeCompact", this.getView(), this.oCommentDialog);

        //this.oCommentDialog.open;
        return this.oCommentDialog;
    },

    onCommentDialogPress: function(oEvent) {
        var oCommentDialog = this._getDialog();
        console.log(oCommentDialog);
        oCommentDialog.open();
    }

CommentDialog.fragment.xml

<core:FragmentDefinition
xmlns="sap.m"
xmlns:core="sap.ui.core">
<Popover
    title="Comments"
    class="sapUiContentPadding"
    placement="Top">
    <footer>
        <Toolbar>
            <ToolbarSpacer/>
            <Button
                id="email"
                text="Email"
                press="handleEmailPress" />
        </Toolbar>
    </footer>
</Popover>

Here is the error i get in the console.

未捕获类型错误:oCommentDialog.open 不是函数

来自 console.log(oCommentDialog); 的错误上方的行有一个返回函数或原型(prototype)。 所以我知道这是有效的,或者至少我认为。

我已经检查过 OPEN() 是否在代码中设置为其他内容,但事实并非如此。

最佳答案

您使用的是 Popover,它没有 open 方法。 如果您想打开 Popover,您需要使用 myPopover.openBy(control) .

您可以找到文档here

事实上,您正在尝试使用 open,并且考虑到您的变量名称,看起来您可能正在寻找 Dialog控制。

关于javascript - SAPUI5 片段无法打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45466581/

相关文章:

javascript - 与页面中的多个图表交互

html - Bootstrap : when navbar collapsed branding overlapping other objects

javascript - 如何调整页面在点击轮播时滚动到中心?

android - 如何将 fragment 与 Viewpager 一起用于滑动页面

android - 具有多个不同大小的 View /fragment 的 ViewPager/ScrollView

javascript - 将 ng-src 的值传递给 ng-model - AngularJs 签名指令

javascript - React.JS 中的 Sails.JS 全局变量

javascript - 有 2 个参数的 Angular 路线不起作用

html - 哪些元素是 "valid"放在 <td> 标签内?

java - 无法将 Intent 附加信息从 Activity 传递到 Viewpager 内的 fragment