React.js:从逻辑中剥离HTML和ASCII字符

时间:2019-07-14 16:49:09

标签: reactjs

如何在此过滤器函数的逻辑内从数据中剥离HTML和ASCII类型的字符?

render() {
   const {
      preferences,
      category,
      headerText,
      renderSaveButton,
      handleSaveResults
    } = this.props;
const filteredPreferences = preferences.filter(
      i => i.category === category && i.key
    );

我这样尝试过:

const filteredPreferences = preferences.filter(
      i => i.category.replace("@<[/!]*?[^<>]*?>@si", "") === category && i.key
    );

及其它的其他变体,但到目前为止,它什么也没做。 preferences来自:

 this.props 
{category: "MemberBenefitInterests", handleSaveResults: ƒ, renderSaveButton: ƒ, data-qa-node: "ComposedComponent", data-qa-file: "withLoading", …}
actions: {preferences: {…}}
category: "MemberBenefitInterests"
currentUser: {id: "1f63ff21-e54a-46d3-b727-97a6db98d43b", settings: {…}, token: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6W…jAifQ.-E-lgUcxmh77QCKUzRp_5cvej6hzhsFZBa9LPyDe6Bo", type: "PrimaryContact"}
data-qa-file: "withLoading"
data-qa-node: "ComposedComponent"
emailContact: true
emailFormatType: "HTML"
handleSaveResults: ƒ ()
isLoading: false
phoneContact: true
preferences: Array(23)
0: {key: "3741cf44-09ba-43f7-adaf-07594f9ec1ad", category: "CommunicationPreferences", code: "Special Offers and Events", name: "Special Offers and Events", description: "Special Offers and Events", …}
1: {key: "1fa9247c-9687-4dec-83c0-0fec84282b52", category: "CommunicationPreferences", code: "Legislative Issues and Alerts", name: "Legislative Issues and Alerts", description: "Legislative Issues and Alerts", …}
2: {key: "39089b50-7b7a-4bb9-990c-164fc77ab318", category: "CommunicationPreferences", code: "NFIB News", name: "NFIB News", description: "NFIB News", …}
3: {key: "153d327e-37ef-436b-ba42-1b1694b6cd8a", category: "CommunicationPreferences", code: "Webinars", name: "Webinars", description: "Webinars", …}
4: {key: "37970319-9327-4f43-aa45-67f6eb25b854", category: "CommunicationPreferences", code: "Partner Offers and Promotions", name: "Partner Offers and Promotions", description: "Partner Offers and Promotions", …}
5: {key: "6e497bce-c46a-4387-96dd-9678a2a24191", category: "CommunicationPreferences", code: "Member Benefits", name: "Member Benefits", description: "Member Benefits", …}
6: {key: "c0f35be9-2863-4fda-bb12-6da97cb70ab9", category: "CommunicationPreferences", code: "Campaigns and Politics", name: "Campaigns and Politics", description: "Campaigns and Politics", …}
7: {key: "6c94984e-c169-4aa5-a27d-54c812e6b4d3", category: "MemberPrivacy", code: "Appear in the Member Directory", name: "Appear in the Member Directory", description: "Appear in the Member Directory", …}
8: {key: "7f2ed28a-d491-4e83-b445-1dfe6f4dc77a", category: "MemberPrivacy", code: "Not Share my Business Phone", name: "Not Share my Business Phone", description: "Not Share my Business Phone", …}
9: {key: "fd6b295b-ecea-4993-98c5-524ad2a559ac", category: "MemberPrivacy", code: "Not Share My Business eMail", name: "Not Share My Business eMail", description: "Not Share My Business eMail", …}
10: {key: "f20d909c-cc64-4fbf-bef7-c1bd73dd2077", category: "MemberPrivacy", code: "Share My Business Address", name: "Share My Business Address", description: "Share My Business Address", …}
11: {key: "392b4843-f424-4956-b149-1db4fa9a44b4", category: "GetInvolved", code: "Will Host Event", name: "Will Host Event", description: "Host a Candidate for an NFIB Event", …}
12: {key: "6e6f4745-5493-4597-90ba-d0f1bf3e3ab7", category: "GetInvolved", code: "Will Testify", name: "Will Testify", description: "Testify at the state or federal Level", …}
13: {key: "c290e416-f2bf-4626-8149-fb047386e4f4", category: "GetInvolved", code: "Volunteer Opps", name: "Volunteer Opps", description: "Volunteer", …}
14: {key: "192fe336-e7e9-45d3-8ace-90d6dc367fa4", category: "GetInvolved", code: "Will Talk to Media", name: "Will Talk to Media", description: "Speak to the Press", …}
15: {key: "55cb0bbc-84bb-4323-a5fb-b5c0489672ed", category: "GetInvolved", code: "ContactRep", name: "ContactRep", description: "Contact my representatives", …}
16: {key: "afd0faa2-4fda-4ff1-b55a-c81251100ebf", category: "GetInvolved", code: "SubmitLetter", name: "SubmitLetter", description: "Submit a Letter to the Editor drafted with the help of NFIB", …}
17: {key: "04cc3c70-6c81-4408-b479-ad0923fcda77", category: "GetInvolved", code: "SpeakCamera", name: "SpeakCamera", description: "Speak on Camera about an issue for an NFIB-produced video", …}
18: {key: "c6ee505e-063a-4b98-8ccd-20d1cfdbd98e", category: "GetInvolved", code: "Attend an NFIB event", name: "Attend an NFIB event", description: "Attend an NFIB event", …}
19:
category: "MemberBenefitInterests"
code: "Business Products and Services"
description: "<div>*Dell &#8211; Save up to 40% on select Dell systems. Available for members and their employees</div><div>*Deluxe &#8211; new Deluxe customers save up to 60% off their first order. Existing customers and new customers future orders save up to 30%. Available for members and their employees.</div><div>*FedEx &#8211; Save up to 20% on select FedEx Office&#174; services, 26% on Express&#174;, 20% on International&#174;, 12% on Ground&#174; and up to 78% on Freight</div><div>*Office Depot &#8211; Discounts up to 65% off the list price on the 1,025 &#8220;Best Value ItemsSprint &#8211; Save up to 25% on applicable </div><div>*Sprint plans, solutions, and accessoriesUniFirst - Uniform and facility service savings of 20-40% off &#8220;local&#8221; pricing</div><div>*WEX &#8211; Save up to 15% on fuel management expenses</div>"
displayText: "<div>*Dell &#8211; Save up to 40% on select Dell systems. Available for members and their employees</div><div>*Deluxe &#8211; new Deluxe customers save up to 60% off their first order. Existing customers and new customers future orders save up to 30%. Available for members and their employees.</div><div>*FedEx &#8211; Save up to 20% on select FedEx Office&#174; services, 26% on Express&#174;, 20% on International&#174;, 12% on Ground&#174; and up to 78% on Freight</div><div>*Office Depot &#8211; Discounts up to 65% off the list price on the 1,025 &#8220;Best Value ItemsSprint &#8211; Save up to 25% on applicable </div><div>*Sprint plans, solutions, and accessoriesUniFirst - Uniform and facility service savings of 20-40% off &#8220;local&#8221; pricing</div><div>*WEX &#8211; Save up to 15% on fuel management expenses</div>"
isSelected: false
key: "719ba5df-53dc-4269-b8c4-1a2f5867e81d"
name: "Business Products and Services"
order: 1
__proto__: Object
20: {key: "a08c1949-d0cd-4dff-9c38-2725caa4f6c2", category: "MemberBenefitInterests", code: "Commercial Insurance", name: "Commercial Insurance", description: "<div>*NFIB Health Insurance Exchange - Average sav…8211; Data breach and cybercrime protection</div>", …}
21: {key: "e163b1aa-e030-4914-b70a-6cea935c30da", category: "MemberBenefitInterests", code: "Financial Products and Services", name: "Financial Products and Services", description: "<div>*BenefitMall &#8211; Save 10% on payroll serv…Access Free Analysis and Savings Comparison</div>", …}
22: {key: "55569cc3-08c6-4db6-8d7c-5bb32396bd9a", category: "MemberBenefitInterests", code: "Personal Insurance", name: "Personal Insurance", description: "<div>*Liberty Mutual &#8211; Save an average of $7…alth plans and Supplemental plans available</div>", …}
length: 23

请注意,this.props.preferences.description中如何包含div和其他字符?那就是我要清理的东西。

0 个答案:

没有答案