0

我正在尝试创建一个简单的小部件 Backbase,但是,它向我显示了一个错误 ReferenceError: requireWidget is not defined。我认为它与 RequireJS 相关,但他的钩子本身并没有做任何事情。也许有人知道如何处理它?

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();
    }
});
4

1 回答 1

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
于 2015-12-28T10:03:25.623 回答