Javascript ExtJS6-网格搜索
我试着用另一种方式申请。当我在Javascript ExtJS6-网格搜索,javascript,search,extjs,grid,Javascript,Search,Extjs,Grid,我试着用另一种方式申请。当我在console.log上尝试时,它似乎运行时没有错误,但当我在function(){}上尝试时,它会变成错误所有网格方法都未定义,例如: 未捕获的TypeError:无法调用未定义的方法“getView” 职能: onTextFieldChange = function () { var grid = Ext.getCmp('grid'), value = Ext.getCmp('gridfield'),
console.log
上尝试时,它似乎运行时没有错误,但当我在function(){}
上尝试时,它会变成错误所有网格方法都未定义,例如:
未捕获的TypeError:无法调用未定义的方法“getView”
职能:
onTextFieldChange = function () {
var grid = Ext.getCmp('grid'),
value = Ext.getCmp('gridfield'),
view = grid.getView(),
columns = grid.getColumns();
view.refresh();
grid.searchValue = value.getValue();
grid.matches = [];
grid.currentIndex = null;
if (grid.searchValue !== null) {
grid.store.each(function (record, index) {
var node = view.getNode(record),
count = 0;
if (node) {
Ext.Array.forEach(columns, function (column) {
var cell = Ext.fly(node).down(column.getCellInnerSelector(), true),
matches,
cellHTML,
seen;
if (cell) {
matches = cell.innerHTML.match(grid.tagsRe);
cellHTML = cell.innerHTML.replace(grid.tagsRe, grid.tagsProtect);
cellHTML = cellHTML.replace(grid.searchRegExp, function (m) {
++count;
if (!seen) {
grid.matches.push({
record: record,
column: column
});
seen = true;
}
return '<span class="' + grid.matchCls + '" style="font-weight: bold;background-color: yellow;">' + m + '</span>';
}, grid);
Ext.each(matches, function (match) {
cellHTML = cellHTML.replace(grid.tagsProtect, match);
});
// update cell html
cell.innerHTML = cellHTML;
}
});
}
});
}
};
有什么建议吗?如果没有,我会回答我自己的问题,这是onTextFieldChange()方法
onTextFieldChange=函数(){
var me=Ext.getCmp('grid'),
计数=0;
me.view.refresh();
me.searchValue=getSearchValue();
me.index=[];
me.currentIndex=null;
如果(me.searchValue!==null){
me.searchRegExp=new RegExp(me.searchValue,'g'+(me.caseSensitive?'i');
me.store.each(函数(记录,idx){
var td=Ext.fly(me.view.getNode(idx)).down('td'),
单元格,匹配项,单元格HTML;
而运输署(运输署){
单元格=td.down('.x-grid-cell-inner');
matches=cell.dom.innerHTML.match(me.tagsRe);
cellHTML=cell.dom.innerHTML.replace(me.tagsRe,me.tagsProtect);
//填充索引数组,设置currentIndex,并替换范围中的换行匹配字符串
cellHTML=cellHTML.replace(me.searchRegExp,函数(m){
计数+=1;
if(Ext.Array.indexOf(me.indexes,idx)=-1){
me.index.push(idx);
}
如果(me.currentIndex==null){
me.currentIndex=idx;
}
返回“+m+”;
});
//还原受保护的标记
Ext.each(匹配,函数(匹配){
cellHTML=cellHTML.replace(me.tagsProtect,match);
});
//更新单元格html
cell.dom.innerHTML=cellHTML;
td=td.next();
如果(me.currentIndex!==null){
me.getSelectionModel().select(me.currentIndex);
}
}
}(我),;
}
//未找到任何结果
如果(me.currentIndex==null){
me.getSelectionModel().deselectAll();
}
};
xtype: 'textfield',
name: 'searchField',
id: 'txtfield',
hideLabel: true,
width: 200,
change: onTextFieldChange()
onTextFieldChange = function () {
var me = Ext.getCmp('grid'),
count = 0;
me.view.refresh();
me.searchValue = getSearchValue();
me.indexes = [];
me.currentIndex = null;
if (me.searchValue !== null) {
me.searchRegExp = new RegExp(me.searchValue, 'g' + (me.caseSensitive ? '' : 'i'));
me.store.each(function (record, idx) {
var td = Ext.fly(me.view.getNode(idx)).down('td'),
cell, matches, cellHTML;
while (td) {
cell = td.down('.x-grid-cell-inner');
matches = cell.dom.innerHTML.match(me.tagsRe);
cellHTML = cell.dom.innerHTML.replace(me.tagsRe, me.tagsProtect);
// populate indexes array, set currentIndex, and replace wrap matched string in a span
cellHTML = cellHTML.replace(me.searchRegExp, function (m) {
count += 1;
if (Ext.Array.indexOf(me.indexes, idx) === -1) {
me.indexes.push(idx);
}
if (me.currentIndex === null) {
me.currentIndex = idx;
}
return '<span class="' + me.matchCls + '">' + m + '</span>';
});
// restore protected tags
Ext.each(matches, function (match) {
cellHTML = cellHTML.replace(me.tagsProtect, match);
});
// update cell html
cell.dom.innerHTML = cellHTML;
td = td.next();
if (me.currentIndex !== null) {
me.getSelectionModel().select(me.currentIndex);
}
}
}, me);
}
// no results found
if (me.currentIndex === null) {
me.getSelectionModel().deselectAll();
}
};