Dojo Toolkit在运行时创建动态小部件

时间:2015-08-04 08:35:40

标签: javascript dojo widget

我对Dojo和1.10版本都很陌生。 我正在寻找一种解决方案,可以根据服务器请求的数据在运行时创建一个小部件。

该应用程序有一棵树。如果单击树中的项目,则应创建新选项卡,并执行脚本以从服务器获取数据并创建窗口小部件。 (在大多数情况下,它是一种形式,来自服务器的数据描述了输入的类型)。脚本的位置存储在树节点中。

在我的应用程序中,我可以点击树节点 - >创建内容窗格并将其添加为选项卡。在contentpane中,href-attribute设置为静态.html-site,如下所示:

dynWidget.html?scriptlocation=abc

在.html文件中,我尝试通过location属性从URL中读取参数。当然,这不起作用,因为location属性包含完整站点的URL而不是内容窗格中附加的URL。

是否有可能从contentpane获取href属性? 这个问题有完全不同的解决方案吗?

任何帮助表示赞赏! 非常感谢你!

2 个答案:

答案 0 :(得分:0)

您的问题可以更详细,但也许您需要:

var node = dojo.byId("contentpane");
var value = domAttr.get(node, "href-attribute");

答案 1 :(得分:0)

  • 在专用商店中保存有关树项的数据
  • 使用Object Pool Pattern保存已打开的标签列表
  • 使用requireWidget.addChild()

    // Custom name for click event handler. Replace to own.
    onItemClick: function(item) {
        // Getting data from store. Any item have full path to widget.
        var dataItem = store.get(item.id),
            requirePath = dataItem.requirePath; // Full path to widget
    
        // Load widget via require function
        require([ requirePath ], function(LoadedWidget){
            var newTab = new ContentPane({}),
                newWidget = new LoadedWidget({});
    
            // Append tab in the global tabs store
            desktop.tabs.add(newTab);
    
            // Place new widget to tab
            newTab.addChild(newWidget);
    
            // Run new widget:
            newWidget.startup();
        });
    }
    

也是在运行时创建小部件的示例:

define([
    "dojo/dom-construct",
    "dojo/_base/declare",
    "dijit/_WidgetBase"
], function(
    domConstruct,
    declare,
    _WidgetBase
){
    return declare(
        "My.Widget.Name", 
        _WidgetBase,
        {
            buildRendering: function(){
                this.inherited(arguments); // Call parent method
                this.domNode = domConstruct.create("div", {
                    // Detail properties of DOM element
                });
                this._button = domConstruct.create("button", {
                    label: "OKAY"
                });
            },

            _okBtnHandler: function(event) {
                // Handler for click by OKAY button

                console.log(this); // Instance of widget, not button DOM node
            },

            startup: function(){
                this.inherited(arguments);

                // Connect handlers to widget dom elements
                // Also, "this" for handler now is My.Widget.Name instance, not DOM Button element
                this.connect(this._button, "onClick", "_okBtnHandler"); 
            }
        }
 );
});
相关问题