简体   繁体   English

集成Ext.js和jscolor

[英]Integrate Ext.js and jscolor

I am unable to integrate this Javascript color picker into my app. 我无法将此Javascript颜色选择器集成到我的应用中。 I use the following code: 我使用以下代码:

jscolor installation: jscolor安装:

<script src="jscolor.js"></script>
Color: <input class="jscolor" value="ab2567">

http://jscolor.com/ http://jscolor.com/

Ext. 分机。 js part: js部分:

xtype: 'component',
    cls: 'jscolor',
    componentCls: 'jscolor',
    html: {
        html: '<input  type= "text" class="jscolor" />'
    },
    itemId: 'colorPicker',
    listeners: {
        afterrender: {
            fn: me.onComponentAfterRender,
            scope: me
        }
    }
},

When the form is rendered the input type is not rendered as a color picker. 呈现表单时,输入类型不会呈现为颜色选择器。 What am I missing here. 我在这里想念的是什么

I don't know exactly where the error came from, but if you want to render only the input (with no field label), I suggest to us autoEl config: 我不知道错误的确切来源,但是如果您只想渲染输入(没有字段标签),我建议我们使用autoEl config:

xtype: 'component',
cls: 'jscolor',
autoEl: {
    tag: "input",
    type: "text"
},
itemId: 'colorPicker'
listeners: {
    afterrender: {
        fn: me.onComponentAfterRender,
            scope: me
        }
    }
}

If you want to still have a proper ExtJS field with value, fieldLabel, etc... capabilities, you will have to extend a Ext.form.field.Base and see how to add the cls to the inputEl (shouldn't be very complicated, you might do this on a afterRender method or change the inputAttrTpl ). 如果您仍然想要具有值,fieldLabel等功能的正确ExtJS字段,则必须扩展Ext.form.field.Base并查看如何将cls添加到inputEl (不是很复杂,您可以在afterRender方法上执行此操作,或更改inputAttrTpl )。

EDIT: And it seems you need to call jscolor.init() after the rendering of you component !!! 编辑:看来您需要在渲染组件调用jscolor.init() EDIT2: using ExtJs 4.2, xtype is not recognize so you need to create your component with Ext.create('widget.component, {...}) EDIT2:使用ExtJs 4.2,无法识别xtype因此您需要使用Ext.create('widget.component, {...})创建组件

Hope it helps 希望能帮助到你

Working Fiddle: https://fiddle.sencha.com/#fiddle/15q9 工作小提琴: https : //fiddle.sencha.com/#fiddle/15q9

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM