English 中文(简体)
ES6 中如何获取搜索过滤数据
原标题:How do get search filter data in es6
/ 基于字符串值的过滤器行, 并且从白列表中排除 白列表 列表 = 行.map (sel = sel = sel. sel. RowerAutoID); // ID 组列以排除控制台.log (白列表, 白列表); / 假设您从输入字段中动态地获得搜索 ltem =$ (. controlData. mendix- react- 物质表格 ) 。 MuiInputBase- put. val () { const = lawerCase (); 控制器.log (搜索范围, 搜索范围); / 创建新的对象阵列, 排除规则属性让过滤器 Rows = 行数. map ({ Ruuto, est } 休息区); 控制台( {rusionRows, 过滤器, liverows) =. (cloax) === lival lival lix ==x = tril=x ==xxxxxxxxxxxxxxxxx ==xxxxxxxxxxxxxxxxxxxxxx
问题回答
You can use filter() rather than using map() operator to exclude RuleAutoIDs. Make sure whenever the input value changes searchTerm gets updated. Finally, you can use to toLowerCase() and includes() to find substring matches in lowercase. Refer to the code below: const rows = [{ RuleAutoID: 1, name: John Doe , age: 30 }, { RuleAutoID: 2, name: Jane Smith , age: 25 }, { RuleAutoID: 3, name: Mark Johnson , age: 35 } ]; const whiteList = [2]; function displayFilteredData(filteredData) { const tbody = document.getElementById( filteredData ); tbody.innerHTML = ; filteredData.forEach(row => { const tr = document.createElement( tr ); tr.innerHTML = `${row.RuleAutoID}${row.name}${row.age}`; tbody.appendChild(tr); }); } function setWhiteList() { const whiteListInput = document.getElementById( whiteList ).value; whiteList = whiteListInput.split( , ).map(id => parseInt(id.trim())).filter(id => !isNaN(id)); console.log( whiteList , whiteList); } function setWhiteList(filteredData) { const tbody = document.getElementById( filteredData ); tbody.innerHTML = ; filteredData.forEach(row => { const tr = document.createElement( tr ); tr.innerHTML = `${row.RuleAutoID}${row.name}${row.age}`; tbody.appendChild(tr); }); } function filterData() { const searchTerm = document.getElementById( searchTerm ).value.toLowerCase(); console.log( searchTerm , searchTerm); const filteredRows = rows.filter(row => !whiteList.includes(row.RuleAutoID)); console.log( filteredRows , filteredRows); const filteredData = filteredRows.filter(row => { const values = Object.values(row).filter(val => val !== null && val !== undefined && val !== ); console.log( values for row , row, values); return values.some(val => { console.log( checking value , val, against searchTerm , searchTerm); return typeof val === string && val.toLowerCase().includes(searchTerm); }); }); console.log( filteredData , filteredData); displayFilteredData(filteredData); } document.getElementById( filterButton ).addEventListener( click , filterData); displayFilteredData(rows.filter(row => !whiteList.includes(row.RuleAutoID))); .table { width: 100%; border-collapse: collapse; } .table th, .table td { border: 1px solid black; padding: 8px; text-align: left; }

Filter Data Sample


Filtered Data

RuleAutoID Name Age




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签