小编Fac*_*uch的帖子

如何使用多个复选框来过滤Angular 2中的数据

我正在使用Angular 2创建一个过滤器页面.数据将根据选中的复选框进行过滤.

这是HTML

    <input required type="checkbox" name="checkbox" value="value1" (change)="toggleFilter(kind.value)" #kind/>
    Filter option 1

    <input required type="checkbox" name="checkbox" value="value2" (change)="toggleFilter(kind2.value)" #kind2 />
    Filter option 2

    <input required type="checkbox" name="checkbox" value="value3" (change)="toggleFilter(kind3.value)" #kind3 />
    Filter option 3


<div *ngFor="let item of (items | FilterPipe: filterFormat)">
    {{item.id}} {{item-title}}
</div>
Run Code Online (Sandbox Code Playgroud)

这是我的Item组件的一部分.在toggleFilter()i中filterOptions,使用复选框的值来填充数组.在get filterFormat()返回所填充的阵列,并把它作为一个参数Filterpipe(其位于HTML)

filterOptions: [] = [];

toggleFilter(value: any) {

    let index = this.filterOptions.indexOf(value);

    if (index > -1) {
      this.filterOptions.splice(index, 1);
    } else {
      this.filterOptions.push(value);
    }

    return …
Run Code Online (Sandbox Code Playgroud)

pipe pipes-filters angular

6
推荐指数
0
解决办法
1744
查看次数

基于 prop 的动态样式组件标签

我正在尝试使用样式组件创建动态标签。标签是通过 props 接收的。

这是代码示例:

import * as React from 'react';
import styled from 'styled-components';

type ContainerProps = {
    children: React.ReactNode,
    type?: 'section' | 'div' | 'article',
}

const Container = styled.div`
  color: ${props => props.theme.primaryColor};
`;

const Icon = styled.div<ContainerProps>`
    background-color: red;
`;

const container: React.FunctionComponent<ContainerProps['children']> = ({ children, type = 'section' }: ContainerProps) => {
    return (
        <Container>
            <{ children }
        </Container>
    );
};

export default container;

Run Code Online (Sandbox Code Playgroud)

我试图实现标签<Container>(现在div)是基于prop.type.

typescript reactjs styled-components

2
推荐指数
1
解决办法
4081
查看次数