ExtJS 6.x (6.5.2) 现代自定义组件

托尼·J·沃森

我想在 ExtJS 6.5.2 Modern 中创建一个自定义组件。没有任何文档明确说明如何执行此操作。

自定义组件是在一个 div 中创建一个链接......例如

{
    xtype: 'test-link',
    urlPart: 'http://www.google.com',
    hashPart: '#test/test/test',
    text: 'example-text'
}

哪个会产生 **<div><a href="http://www.google.com#test/test/test">example-text</a></div>**

  1. 我应该如何构建自定义组件?
  2. 为什么在下面的示例中设置 config.template 不起作用?构造函数不先运行吗?
  3. 我应该如何更新该自定义组件上的参数?

调试和示例代码如下:

Ext.application({
    name : 'Fiddle',

    launch : function() {
         Ext.define('LinkTest', {
           extend: 'Ext.Component',
             xtype: 'test-link',

             // looks like parameters go here
             // config: {

             // },

             // No idea what cached config is for
             // cachedConfig: {

             // },


             constructor: function(config) {
                console.log('STEP 1. constructor - at start')
               // This returns the config so we know it works
                 console.log(config.urlPart, config.hashPart, config.text)

                 // Just an example of a dynamic configuration option
                 // we may have to do in the setup process
                 config.href = config.urlPart + config.hashPart

                 // This doesn't work even though it works if done inline
                 // this makes no sense to me, because AFAIK adding stuff onto
                 // the config here should be identical as directly creating 
                 // it.


                 config.template = [
                  {
                    tag: 'a',
                    text: config.text,
                    href: config.href,
                    refence: 'anchorTag'
                  }
                 ]

                 //### THis also doesn't work
                 //  config.template = [
               //   {
               //     tag: 'a',
               //     text: 'test.com text',
               //     href: 'htts://test.com/url',
               //     reference: 'anchorTag'
               //   }
               // ]



                 console.log('STEP 2. constructor - before callParent')
                 this.callParent(arguments)
                 console.log('STEP 3. constructor - before callParent')

             },

             // THIS CODE WORKS BUT IS NOT DYNAMICALLY GENERATED
             // so commented out for now
             // template: [
             //   {
             //     tag: 'a',
             //     text: 'test.com text',
             //     href: 'htts://test.com/url',
             //     reference: 'anchorTag'
             //   }
             // ],

             initialize: function() {
              console.log('STEP 3. initialize - at start')
              console.log('template', this.template)
              console.log('in initialize', this.href) // << works returns the full url

             }
         })


        Ext.Viewport.add({
            xtype: 'panel',
            layout: 'fit',
            title: 'Example',
            items: [{
                xtype: 'test-link',
                urlPart: 'http://www.google.com',
                hashPart: '#test/test/test',
                text: 'example-text'
            }]
        });;
    }
});
埃文·特林博利

像这样的东西:

Ext.define('Link', {
    extend: 'Ext.Component',
    xtype: 'link',

    element: {
        reference: 'element',
        tag: 'a'
    },

    config: {
        url: null,
        hash: null,
        text: null
    },

    updateUrl: function () {
        this.computeUrl();
    },

    updateHash: function () {
        this.computeUrl();
    },

    updateText: function (text) {
        this.el.dom.innerText = text;
    },

    computeUrl: function () {
        var url = this.getUrl() || '',
            hash = this.getHash() || '';

        this.el.dom.href = url + hash;
    }
});

用法:

Ext.application({
    name: 'Fiddle',

    launch: function () {
        Ext.Viewport.add({
            xtype: 'container',
            items: [{
                xtype: 'link',
                url: 'google.com',
                text: 'Link only'
            }, {
                xtype: 'link',
                hash: '#foo',
                text: 'Hash Only'
            }, {
                xtype: 'link',
                url: 'google.com',
                hash: '#foo',
                text: 'Both'
            }]
        });
    }
});

小提琴

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

extjs 6网格自定义标头

来自分类Dev

extjs 6网格自定义标头

来自分类Dev

Extjs6 自定义 js 事件

来自分类Dev

ExtJS6扩展组件

来自分类Dev

带有自定义配置绑定的 Extjs6 自定义按钮

来自分类Dev

extjs6 现代卡片布局

来自分类Dev

在extjs6应用程序构建中添加自定义文件

来自分类Dev

在ExtJs 6中加载商店时如何发送自定义过滤器参数

来自分类Dev

ExtJs 6 的全局函数

来自分类Dev

AEM 6:如何自定义Reviews Essentials组件

来自分类Dev

Angular 6 - 自定义模态窗口内的嵌套组件

来自分类Dev

创建和主题化ExtJS 6组件

来自分类Dev

创建和主题化ExtJS 6组件

来自分类Dev

extjs6,扩展图表组件以适合列

来自分类Dev

(-6x ^ 2-x-7)(2x ^ 3 + 3x ^ 2-2x-5)作为SymPy中的输入

来自分类Dev

extjs 6 grid custom header

来自分类Dev

Extjs 6 viewModel和存储

来自分类Dev

使用ExtJS 6拖放文件

来自分类Dev

Extjs 6 viewModel和存储

来自分类Dev

从ExtJS 4.2迁移到6

来自分类Dev

堆栈 ExtJS 6 + Spring Boot

来自分类Dev

ExtJS 6 - 可滚动的 GridPanels

来自分类Dev

iPhone5和iPhone6 @ 2x图像问题

来自分类Dev

Ember 2.x组件中的自定义templateName

来自分类Dev

如何使Unity 5.x支持C#5或6?

来自分类Dev

仅使用VSTA在Corel Draw X6中创建自定义控件

来自分类Dev

仅使用VSTA在Corel Draw X6中创建自定义控件

来自分类Dev

ASP.NET 5 MVC6自定义CSS和Javascript放置约定

来自分类Dev

Asp.net 5 MVC 6自定义身份验证