ReactGridLayout:ReactGridLayout.children [0] .x必须为数字

时间:2019-07-04 06:56:33

标签: javascript reactjs react-grid-layout

我为我删除的网格设置

im设置列表添加,然后将其存储到列表数据中,它在以前可以正常工作,但是当我尝试立即添加但出现此错误时。 ReactGridLayout:ReactGridLayout.children [0] .x必须是数字!

 listAdd(x){

        let addItems = [...this.state.addItems];
        let items = [...this.state.items];

        items.push(x)
        addItems.splice(addItems.indexOf(x),1)
        console.log(items, 'uitems');
        console.log(addItems, 'items')
        this.setState({
            items: items,
            addItems: addItems
        })
    }
getInput(key){
        //let ls = {};
        let value = localStorage.getItem("layoutsJR") || {};
        //ls = JSON.parse(localStorage.getItem("layoutsJR")) || {};
        try{
            //parse localstorage string dan set state
            value = JSON.parse(value)
            this.setState({
            [key]: value
            })
        }catch(e){
            //handle empty string
            this.setState({
            [key]: value
            })
        }
        //console.log(value[key], "get inputan move")
        return value[key]


        // return ls[key];
    }

    updateInput(key, value){
        this.setState({
            [key] : value
        })

        localStorage.setItem(key, JSON.stringify({[key]: value}))
    }
onRemoveItem(i){

        let addItems = [...this.state.addItems];
        let items = [...this.state.items];
        addItems.push(items[i]);
        items.splice(i, 1);
        this.setState({
            addItems : addItems,
            items :items
        })
    }
 class AddRemoveLayout extends React.Component{
    // static get defaultProps() {
    //     return {
    //     className: "layout",
    //     cols: {lg: 12, md: 10, sm: 6, xs: 4, xxs: 2},
    //     rowHeight: 100,
    //     onLayoutChange: function(){}
    //     }
    // };

    constructor(props){
        super(props);

        this.state={
            itemsDefault :[0, 1, 2, 3, 4, 5].map(function(i){
                return{
                    i: i.toString(),
                    x: i*2,
                    y: 2,
                    w: 3,
                    h: 3
                };
            }),
            items: [0, 1, 2, 3, 4, 5].map(function(i){
                return{
                    i: i.toString(),
                    x: i*2,
                    y: 2,
                    w: 3,
                    h: 3
                };
            }),
            addItems:[],
            fullScreen: true,
            tempSisa: null,
            addItemsSisa: [],
            quantity:"",
            showWidget: false,
            isChecked: true,
            product: '',
            layouts: JSON.parse(JSON.stringify(this.getInput("layoutsJR")|| []))

        };
render(){
        let items = this.state.items;
        let addItems = this.state.addItems;

        return(
            <div>
                {this.state.fullScreen ? 
                    <div class="buttonMenu">


                <Dropdown class="dropdownList">
                    <Dropdown.Toggle variant="success" id="dropdown-basic">
                        List Add
                    </Dropdown.Toggle>

                    <Dropdown.Menu>
                      {addItems.map((index) =>{
                          return <Dropdown.Item key={index} onClick={this.listAdd.bind(this, index)}>{index.i}</Dropdown.Item>
                      })}
                    </Dropdown.Menu>
                </Dropdown></div> : <div></div>}

                <ResponsiveReactGridLayout

                    className="layout"
                    cols={{lg: 12, md:10, sm:6, xs:4, xxs:2}}
                    rowHeight={30}
                    layouts={this.state.layouts} 
                    onLayoutChange={(layout, layouts)=>this.onLayoutChange(layout, layouts)} 
                    onBreakpointChange={this.onBreakpointChange} 

                >{_.map(this.state.items, (el, index) => {return this.createElement(el, index)})
                /*this.state.items.map((el, index) => {
                    return this.createElement(el, index)
                })*/
                }
                </ResponsiveReactGridLayout>
            </div>
        );
    }
}

它在我在网格布局中添加表格之前起作用,但是随后出现此错误ReactGridLayout:ReactGridLayout.children [0] .x必须是数字!

0 个答案:

没有答案