2017-06-16 50 views
0
var grid = Ext.getCmp('grid'); 

var matcher = new RegExp(Ext.String.escapeRegex(newValue), "i"); 

是否有人可以向我解释这些代码行?Ext JS正则表达式和getcmp

+0

退房ExtJS的” [API](https://docs.sencha.com/extjs/ 6.2.0/classic/Ext.html#method-getCmp)[docs](https://docs.sencha.com/extjs/6.2.0/classic/Ext.String.html#method-escapeRegex)和Mozilla的[MDN ](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) – scebotari66

回答

1

Ext.getCmp是ExtJS的一种document.getElementById()

你创建了一个元素:

Ext.create('Ext.panel.Panel',{ 
    title: 'Foo', 
    html: 'Bar', 
    id: 'mytest', 
    renderTo: document.body 
}); 

然后运行Ext.getCmp('mytest')将返回该面板的实例,所以你可以做的事情吧,比如:

var panel = Ext.getCmp('mytest'); 
test.setTitle('Hello'); 

创建一个新的正则表达式无关使用ExtJS,这是Javascript的标准方式(其中之一)来创建正则表达式(请参阅:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp)。

Ext.String.escapeRegex将格式化的方式是有效的正则表达式中使用的字符串,以便Ext.String.escapeRegex(abs-$dxjksgg)将返回abs\-\$dxjksgg

+0

谢谢兄弟:) –

+0

没问题,请注意,设置ID和使用Ext.getCmp()是不是最好的选择。尝试使用'Ext.ComponenQuery.query()',以便您可以使用选择器(如CSS选择器)来抓取组件。 –

+0

它实际上是一个代码onTextFieldChange:function(field,newValue,oldValue,options)var grid = Ext.getCmp('grid'); grid.store.clearFilter(); (newValue)var matcher = new RegExp(Ext.String.escapeRegex(newValue),“i”); (record.get('kod'))| gridcher.filter }); } } –