Front-end js implements dynamically adding selected data to the table

As shown in the figure below, there is attribute content above the table. After selecting it from the drop-down list, the selected content is added to the table below.
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Implementation method, (must agree with the backend, because these dynamically added fields are returned by the backend, and the backend will handle it itself. What our frontend needs to do is to map the drop-down data to the table based on the data returned by the backend. And implement addition, deletion, modification and query.)
Generally, the template string method may be used, but sometimes map assignment can be done directly.

as follows.

			<>
            销售属性:
            <Select
              style={
   
   { width: 260, marginRight: 10 }}
              size="small"
              mode="multiple"
              maxTagCount="responsive"
              value={this.props.salesAttrCodes}
              options={this.props.selsetList} // 展示的数据,后端返回,自己调取接口获取后赋值
              onChange={(value) => {
                this.handleChangeSalesAttr(value);
              }}
            />
          </>

	  handleChangeSalesAttr = (value) => {
	    this.props.changeSalesAttrCodes(value);
	    const addrowsData = this.props?.selsetListAll?.filter((item) => {
	      return value.includes(item.catePropCode);
	    });
	    const addrows =
	      addrowsData.length &&
	      addrowsData.map((item) => {
	        let them;
	        if (item?.isHand) {
	          them = { // 表格定义的规则 。
	            title: item.catePropName,
	            width: 180,
	            dataIndex: item.catePropCode,
	            align: 'left',
	            editable: true,
	            rules: [{ required: item.isMust, message: '必填' }],
	            field: () => {
	              return {
	                formOption: {
	                  type: '$textArea',
	                  props: {
	                    showCount: true,
	                    maxLength: 200,
	                    placeholder: '请输入且最多200个字',
	                  },
	                },
	                name: item.catePropCode,
	              };
	            },
	          };
	        } else {
	          them = {
	            title: item.catePropName,
	            width: 180,
	            dataIndex: item.catePropCode,
	            align: 'left',
	            editable: true,
	            rules: [{ required: item.isMust, message: '必填' }],
	            field: () => {
	              return {
	                formOption: {
	                  type: '$select',
	                  props: {
	                    placeholder: '请选择',
	                    options: item.valueNames.split(';').map((item) => {
	                      return {
	                        label: item,
	                        value: item,
	                      };
	                    }),
	                  },
	                },
	                name: item.catePropCode,
	              };
	            },
	          };
	        }
	        return them;
	      });
	      // 重新触发更新表格
	    this.setState({
	      AddTableColumns: addrows,
	    });
	  };

Guess you like

Origin blog.csdn.net/lzfengquan/article/details/132540864