Uncaught TypeError:无法使用"in"运算符在未定义的位置搜索"position" [英] Uncaught TypeError: Cannot use 'in' operator to search for 'position' in undefined

查看:381
本文介绍了Uncaught TypeError:无法使用"in"运算符在未定义的位置搜索"position"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码段存在问题:

<script>
                $.sap.require('sap.ui.thirdparty.jqueryui.jquery-ui-core');
                $.sap.require('sap.ui.thirdparty.jqueryui.jquery-ui-widget');
                $.sap.require('sap.ui.thirdparty.jqueryui.jquery-ui-mouse');
                $.sap.require('sap.ui.thirdparty.jqueryui.jquery-ui-draggable');
                $.sap.require('sap.ui.thirdparty.jqueryui.jquery-ui-sortable');
        </script>
        <script>
                jQuery.sap.includeStyleSheet("resources/css/dashboard.css");
                sap.ui.localResources("dashboard");
                var view = sap.ui.view({id:"idHome1", viewName:"dashboard.Home", type:sap.ui.core.mvc.ViewType.JS});
                view.placeAt("content");
        </script>
        <script>
            var oButton = sap.ui.getCore().byId("oChart_Button");
            console.log(oButton);
            $(document).ready(function(){
                $(oButton).draggable({
                    cancel: false
                })
            })
        </script>

由于标题中的ErroMessage,我无法拖动按钮.我从互联网上得到了这个例子,对于评论此博客的人来说,代码可以运行.该按钮存在,使用console.log(oButton)会收到一条消息,其中包含其属性,依此类推. 有解决方案的人吗?

I can't drag my button, because of the ErroMessage in the title. I've got this example from the internet, and for the people who comment this blog the code runs. The button exists, with console.log(oButton) I get a message with it's properties and so on. Any one a solution?

推荐答案

使用

Use getDomRef to get DOM element of your UI5 control. So, your code will be something like this.

var oButton = sap.ui.getCore().byId("oChart_Button");
var el = oButton.getDomRef();
$(el).draggable({
    cancel: false
});

jQuery选择器允许您选择和操作HTML元素. 当您执行$(oButton)时,您将SAPUI5 Button对象传递给jQuery选择器,该对象将不起作用.因此,要获取UI5 Button控件的相应HTML DOM元素,请使用getDomRef.

jQuery selectors allow you to select and manipulate HTML element(s). When you do $(oButton) you are passing SAPUI5 Button object to jQuery selector, which will not work. So, to get respective HTML DOM element of UI5 Button control, getDomRef is used.

那么,为什么即使将DOM传递给jQuery选择器后,按钮也不能可拖动?

So, why your button is not draggable even after passing DOM to jQuery selector?

之所以会发生这种情况,是因为首先要为可拖动功能加载jQuery-Ui的第三方库. 然后,在加载了SAPUI5库之后,因此只能使用SAPUI5库中的函数. 因此,要解决此问题,我们可以在HTML文件的正文中将第三方库加载到UI5库之后.

This might be happening because first you are loading third party library for jQuery-Ui for draggable functionality. Then, after that SAPUI5 library is loaded, so functions only from SAPUI5 library are available. So, to overcome this, we can load the third party library after UI5 library within body of your HTML file.

这篇关于Uncaught TypeError:无法使用"in"运算符在未定义的位置搜索"position"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆