---
title: "Extjs拓展显示文本控件"
author: "softlife"
date: "2013-12-11T22:12:39Z"
tags: []
categories: ["Web前端"]
slug: "extjs"
draft: false
lastmod: "2013-12-11T22:12:39Z"
id: 1988324
url: "https://softlife.iteye.com/blog/1988324"
---

\[code="extjs"]Ext.StaticTextField = Ext.extend(Ext.form.Field,{ defaultAutoCreate:{tag:"div"}, field:null, value:'--', onRender:function(ct,position){ Ext.StaticTextField.superclass.onRender.call(this,ct,position); Ext.DomHelper.append(this.el,{ tag:'div', style:'height:100%;width:100%;', html:""+this.getValue()+"" }); }, getValue:function(){ if(!this.rendered) { return this.value; } try { var v = this.el.getValue(); if(v === this.emptyText || v === undefined){ v = ''; } }catch(ex){ alert("get value error of "+this.name); } return v; }, setValue:function(v){ this.value = v; if(this.rendered){ this.el.dom.value = (v === null || v === undefined ? '' : v); this.validate(); Ext.DomHelper.overwrite(this.el,{ tag:'div', style:'height:100%;width:100%;', html:""+this.value+"" }); } } }); Ext.reg('StaticTextField',Ext.StaticTextField);\[/code]