使用外部js文件时,javascript全局变量'undefined'

时间:2017-08-28 08:38:47

标签: javascript jquery html5

我目前正在Eclipse中创建一个Design Studio自定义组件。我要做的一件事就是在我的附加属性窗格中调整我的下拉列表。所以在我的'additional_properties_sheet.html'中,我有以下代码:

<html>
<head>
    <title>Annotation property sheet</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script src="/somepath/sdk_propertysheets_handler.js"></script>
    <script src="../js/component.js"></script>

    <script src="additional_properties_sheet.js"></script>
    <script></script>
</head>
<script>
    new com.sap.sample.annotation.AnnotationPropertyPage();
</script>
<body>
    <form id="form">

    <button type="button" onclick="test()">Click me</button>


    </form>

</body>

在我的js文件'component.js中,我有类似于这段代码的东西:

var retrieveObj;
define(["sap/designstudio/sdk/component", "d3", "../js/ckeditor/ckeditor", "css!../css/component.css"], function(Component, d3, ckeditor, css) {
Component.subclass("com.sap.sample.annotation.Annotation", function() {

var me = this;

me.redraw = function(){
//have some code before here to add some layout and stuff

    //they wated some delay on the dropdowns
    var myVar = setTimeout(myTimer, 2000);
    function myTimer() {
        //thediagram is a rectangle to wich I add this dropdown
        commObjDropdown = theDiagram.append("foreignObject")
        .attr("x", "5%")
        .attr("y", "76%")
        .attr("width", "226")
        .attr("height", "30")
        .append("xhtml:body")
        .html('<select name="commObjs" id="commObjs" class="commObjs"></select>');


        retrieveObj=document.getElementById("commOjbs");
        //this alert gives me the object
        alert(retrieveObj);

    }
}

me.init = function() {
        //me.getCalls();
        me.redraw();
        //me.createEditor();
        };

});

function test(){
//here the alert gives me 'undefined'
alert(retrieveObj);
}

每次我点击按钮,它都会返回'undefined'。我需要一种方法来检索我的下拉对象,以便我可以在附加属性窗格中调整它,任何人都知道出路?

0 个答案:

没有答案