ReferenceError:未定义requireWidget

时间:2015-08-19 09:12:46

标签: javascript requirejs js-amd backbase-portal

我正在尝试创建一个简单的小部件Backbase,但是,向我显示错误ReferenceError:requireWidget未定义。我认为它与RequireJS有关,但他的钩子本身没有做任何事情。也许有人知道如何处理它?<​​/ p>

index.html文件:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:g="http://www.backbase.com/2008/gadget" xml:lang="en">
<head>
    <title>Todo Widget</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

    <g:preferences>
        <g:preference name="limit" label="Todo's Limit" type="text" default="5" viewHint="none" />
    </g:preferences>

</head>
<body g:onload="requireWidget(__WIDGET__, 'todo')" class="todo-widget">
    <h1>Todo Widget</h1>
</body>
</html>

和js文件

define(["jquery"], function($) {
    "use strict";

    var self;

    function Todo(widget) {
        self = this;

        self.widget = widget;
        self.$widget = $(widget.body);

        return self;
    }

    Todo.prototype.init = function() {
        window.alert('it works!');
    }

    return function(widget) {
        var todo = new Todo(widget);
        todo.init();
    }
});

1 个答案:

答案 0 :(得分:0)

Basically you need to reference the the require conf file in your HTML FILE from the launchpad.
 **<script src="../../../launchpad/conf/require-conf.js"></script>**
the path ../ depends on the your path of the source folder. 

You can also write the Widget without the require js as below with your own function

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
 xmlns:g="http://www.backbase.com/2008/gadget" xml:lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/xml; charset=UTF-8" />
        <title>Hello World</title>
        <g:preferences>
            <g:preference name="FontSize" type="range" min="8" max="24" step="2"
             default="12" label="Font size" onchange="applyFontSize(__WIDGET__)"
             viewHint="user" />
        </g:preferences>
        <script type="text/javascript">
            function applyFontSize(oWidget) {
                oWidget.body.style.fontSize=encodeURIComponent(oWidget.getPreference('FontSize'))+'px';
            }
        </script>
    </head>
    <body g:onload="applyFontSize(__WIDGET__)">
        <p>Hello World</p>
    </body>
</html>

Also you can register on the http://my.backbase.com.. to have access to more documentation
相关问题