简体   繁体   English

如何在JavaScript中过滤这些搜索结果?

[英]How can I filter these search results in JavaScript?

I have a search.js file (part of a large script) that handles searching through files & folders and returning the results. 我有一个search.js文件(是大脚本的一部分),该文件可以处理文件和文件夹的搜索并返回结果。

I am trying to filter the search results so that any file names or paths that contain "unwanted" are not displayed. 我试图过滤搜索结果,以便不显示任何包含“有害”的文件名或路径。

This is the search.js file in it's entirety: 这是整个search.js文件:

FR = {
    UI: {translations:[]}
};

function setLookInValue() {
    var path = window.parent.FR.searching.path.replace('/ROOT/HOME', '');
    lookin.setValue(path ? path : '/');
    FR.grid.getStore().removeAll();
}

Ext.onReady(function() {
    window.parent.Ext.get(window.parent.FR.UI.searchPopup.getLayout().container.body.dom).unmask();
metadataField = new Ext.form.ComboBox({
    fieldLabel: FR.T('Metadata Field'),
    autoCreate:true, mode: 'local',
    emptyText:FR.T('Select...'),
    displayField:'filetype',
    valueField:'id', name: 'metadata_field_id', hiddenName:'metadata_field_id',
    editable: false, triggerAction:'all', disableKeyFilter: true,
    forceSelection:true, value:0, width:130,
    store: new Ext.data.SimpleStore({
        fields: ['id', 'filetype'],
        data: FR.metadataFields
    })
});
metadataValue = new Ext.form.TextField({
    fieldLabel: FR.T('Metadata'), name: 'metadata_value', width: 130, value: ''
});
FR.rightColumnFields = [];
if (window.parent.User.perms.metadata) {
    FR.rightColumnFields.push(metadataField);
    FR.rightColumnFields.push(metadataValue);
}
FR.rightColumnFields.push(new Ext.Button({
    text: FR.T('Search'),
    style: (!window.parent.User.perms.metadata ? '' : 'margin-left:98px'),
    handler: function(){
         ds.load({
            params:{
                filename: Ext.getCmp('filename').getValue(),
                keyword: Ext.getCmp('keyword').getValue(),
                metafield: metadataField.getValue(),
                metavalue: metadataValue.getValue(),
                path: encodeURIComponent(window.parent.FR.searching.path)
            }
        });
    }
}));

FR.form = new Ext.form.FormPanel({
    labelAlign: 'right',
    labelWidth: 90,
    border: false,
    hideBorders: true,
    bodyBorder: false,
    bodyStyle: 'padding:5px',
    items: [{
        layout:'column',
        items: [{
            columnWidth:.5,
            layout: 'form',
            border: false, bodyBorder: false,
            items: [{
                id: 'filename', xtype:'textfield',
                fieldLabel: FR.T('File name'),
                name: 'file_name', width: 130, value: ''
            },
            {
                id: 'keyword', xtype:'textfield',
                fieldLabel: FR.T('File contents'),
                name: 'file_contents',
                width: 130, value: '',
                disabled: !window.parent.Settings.fullTextSearch
            },
            lookin = new Ext.form.TextField({
                fieldLabel: FR.T('Look in'),
                name: 'lookin', width: 130, value: '', readOnly: true
            })
            ]
        },{
            columnWidth:.5,
            id: 'secondCol',
            layout: 'form',
            border: false,
            bodyBorder: false,
            items: FR.rightColumnFields
        }]
    }]
});

var ds = new Ext.data.Store({
    proxy: new Ext.data.HttpProxy({
        url: URLRoot+'/?module=search&section=ajax&page=search'
    }),
    reader: new Ext.data.JsonReader({
            root: 'files',
            totalProperty: 'totalCount',
            id: 'id'
        }, 
        [
            {name: 'icon'},
            {name: 'id'},
            {name: 'filename'},
            {name: 'path'},
            {name: 'technical_path'},
            {name: 'score', type: 'float'}
        ]
    )
});

var cm = new Ext.grid.ColumnModel({
    defaults: {sortable: true},
    columns: [
        {id: 'filename', header: FR.T("File name"), dataIndex: 'filename', width: 160,
            renderer: function (value, p, record) {
                return '<img src="'+URLRoot+'/images/fileman/file_icons/small/'+record.data.icon+'" width="16" height="16" align="absmiddle"> '+value;
            }
        },
        {id: 'path', header: FR.T("Path"), dataIndex: 'path'}
    ]
});
cm.defaultSortable = true;

grid = new Ext.grid.GridPanel({
    ds: ds,
    cm: cm,
    border: false, bodyBorder: false, hideBorders: true,
    selModel: new Ext.grid.RowSelectionModel({singleSelect:true}),
    loadMask: {msg: FR.T('Searching...')},
    enableColumnHide: false,
    enableColumnMove: false,
    autoExpandColumn: 'path',
    selModel: new Ext.grid.RowSelectionModel({singleSelect:true})
});

grid.on('rowclick', function (grid, rowIndex, e){
    var rowData = grid.getStore().data.items[rowIndex].data;
    var path = rowData.technical_path;
    var filename = rowData.filename;
    if (window.parent.FR.currentPath != path) {
        window.parent.FR.UI.tree.panel.selectPath(path, 'pathname', function() {
            window.parent.FR.UI.grid.highlightOnDisplay = filename;
        });
    } else {
        window.parent.FR.UI.grid.highlight(filename);
    }
});

grid.on('rowcontextmenu', function(grid, rowIndex, e) {e.stopEvent();return false;})
FR.grid = grid;

new Ext.Viewport({
    layout: 'border',
    hideBorders: true,
    items: [
        {
            region: 'north', layout: 'fit', split: true, height:100,
            hideBorders: true, bodyBorder: false, border: false,
            items: [FR.form]
        },
        {
            region: 'center', layout: 'fit', autoHeigh: true,
            items: grid
        }
    ]
});
setLookInValue();
});

I'm pretty lost. 我很迷路。 I thought somewhere in the code I could do something like: 我以为在代码中的某处我可以做类似的事情:

if (someVar.indexOf("unwanted") == -1) { ...

Is there anything in this JavaScript that would give anyone enough info to help me filter these search results? 这个JavaScript中是否有任何东西可以给任何人足够的信息来帮助我过滤这些搜索结果?

This looks like code that uses Ext JS, and I have added a tag accordingly. 这看起来像使用Ext JS的代码,并且我相应地添加了一个标签。 A little sniffing through the documentation suggests that the Filtering and Sorting section of the Ext.data.Store page will put you on the right track. 稍微浏览一下文档说明Ext.data.Store页面的Filtering and Sorting部分将使您走上正确的道路。

暂无
暂无

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

相关问题 如何使用 JavaScript 实时突出显示搜索结果? - How can I highlight search results live with JavaScript? 如何使用 Javascript 从一系列 HTTP 搜索查询中自动打印搜索结果? - How can I use Javascript to automatically print search results from a series of HTTP search queries? 使用 React Hooks 如何让两个搜索输入协同工作以过滤结果 - Using React Hooks How Can I Have two search inputs that work together to filter results 如何通过 .filter() .filter()? JavaScript - How can I .filter() through a .filter()? JavaScript 如何呈现搜索结果列表? - How can I render a list of search results? 使用 Javascript 中的选择框搜索和过滤结果 - Search and filter the results with a choice box in Javascript 如何过滤/搜索多个子数组? - How can I filter/search multiple subarrays? 如何让搜索过滤器循环遍历库存项目表中的 MULTIPLE 数据类型,并缩小显示的结果范围? - How can I get a search filter to loop through MULTIPLE data types in a stock items table, and narrow down what results displayed? 如何使用 JQuery 在画廊上设置搜索过滤器功能? 它需要隐藏与实时键条目不匹配的结果 - How can I set up search filter functionality on a gallery with JQuery? It needs to hide results not matching real time key entries 如何用纯JavaScript重写此jQuery搜索过滤器功能? - How can this jQuery search filter function be rewritten in pure JavaScript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM