PDA

View Full Version : I can't use Ext.Util.TextMetrics ... why ?



mfruizs2
7 Sep 2012, 1:02 AM
I'm trying to use the methods form Ext.util.TextMetrics,

code:


this.setTitle("Hi!");
var width = Ext.util.TextMetrics.getWidth(this.title);
this.setWidth(width);




on chrome debugger:




>"Ext.util.TextMetrics: function () {"



but when expand that function do nothing... can't invoke any method, i got a Exception problem on that code:




and this is the exception that throw:






extjs/src/chart/Tip.js?_dc=1347004442226:86
Uncaught TypeError: Object function () { return this.constructor.apply(this, arguments); }



on console, expanded:






has no method 'getWidth' app/view/myFolder/Reports.js?_dc=1347004442419:86
items.items.series.tips.renderer app/view/myFolder/Reports.js?_dc=1347004442419:86
Ext.define.showTipextjs/src/chart/Tip.js?_dc=1347005147139:86
Ext.define.onItemMouseOverextjs/src/chart/series/Series.js?_dc=1347005147142:258
fireext-debug.js:16976
Ext.define.continueFireEventextjs/src/util/Observable.js?_dc=1347005146725:291
Ext.define.fireEventextjs/src/util/Observable.js?_dc=1347005146725:264
(anonymous function)extjs/src/chart/Chart.js?_dc=1347005147137:612
Ext.define.eachextjs/src/util/AbstractMixedCollection.js?_dc=1347005146698:230
Ext.define.onMouseMoveextjs/src/chart/Chart.js?_dc=1347005147137:595
fireext-debug.js:16976
Ext.define.continueFireEventextjs/src/util/Observable.js?_dc=1347005146725:291
Ext.define.fireEventextjs/src/util/Observable.js?_dc=1347005146725:264
Ext.override.fireEventextjs/src/app/EventBus.js?_dc=1347005147078:35
(anonymous function)extjs/src/draw/Component.js?_dc=1347005146951:236
fireext-debug.js:16976
Ext.define.continueFireEventextjs/src/util/Observable.js?_dc=1347005146725:291
Ext.define.fireEventextjs/src/util/Observable.js?_dc=1347005146725:264
Ext.define.onMouseMoveextjs/src/draw/Surface.js?_dc=1347005146984:468
(anonymous function)
wrap



żAny idea why it happens ?

thx ;)

debabrata
7 Sep 2012, 5:19 AM
HAve you tried getSize (http://localhost/research/resources/4.1/docs/index.html#!/api/Ext.util.TextMetrics-method-getSize) function ?

vietits
7 Sep 2012, 5:52 AM
Ext.util.TextMetrics is a class, not an object, and getWidth() is not a static method. So you should create an instance from it. Example:


var tm = Ext.create('Ext.util.TextMetrics');
console.log(tm.getWidth('123456789'));