Comments (5)
@myronlau AddStorage 组件给 StorageForm 传入了一个属性 onSelect
onSelect(supplierId){
dispatch({
type: 'storage/setSupplier',
payload: {
supplierId
}
})
}
这样, 当 StorageForm 中的 供应商选择 组件值变更时会调用 onSelect 把供应商的 id 传回 AddStorage 中。
DatePicker 类型的日期 为 moment 对象,见 antd RangePicker 在提交之前会转为日期字符串:
const onSubmit = (e) => {
e.preventDefault();
validateFields((errors, values) => {
if (!!errors) {
return false;
}
if (values['timeRange']) {
values['timeRange'] = values['timeRange'].map((time) => time.toLocaleString());
}
onSearch(values);
})
};
这样是为了方便拼接查询字符串,后端接收到日期字符串后传入 new Date(dateString) 得到 Date 对象,作为条件进行数据查询。
有问题继续交流 : )
from accountsystem.
@yvanwangl 谢谢你的回复,根据你的回答问题得到解决了。
现在有个新的问题想再请教你,在AddStorageGrid.jsx中,
onListCellChange(index, key){
const {editProducts} = this.props;
const {totalAmount, paymentAmount} = this.state;
return ({key, label})=> {
const dataSource = [...this.state.dataSource];
const arr = label.match(/([\u4e00-\u9fa5\w]+)/g);
dataSource[index]['productId'] = key;
dataSource[index]['productName'] = arr[0];
dataSource[index]['productUnit'] = arr[1];
this.setState({dataSource});
editProducts(dataSource, totalAmount, paymentAmount);
}
}
其中const arr = label.match(/([\u4e00-\u9fa5\w]+)/g);
怎么理解?应该怎么用呢?
from accountsystem.
@myronlau 这块是这样的,在增加商品的表格中,商品是一个可编辑下拉框,然后在 ListEditableCell 组件中的 Select 中设置了 labelInValue 属性,这样在 Select 组件的 onSelect 事件处理函数的参数对象中就可以获取到选择项的 value 和 label, 详情参考 antd 文档;
由于我的表格中有一列 “单位”, 而单位属性来自于商品,所以在渲染商品的下拉列表时我是这么处理的(代码在 ListEditableCell 组件中):
<Select
defaultValue={{ key: value.key }}
onSelect={this.handleSelect}
onBlur={this.check}
style={{ minWidth: 120, width:'100%' }}
disabled={disabled || false}
labelInValue
>
{
productList.map(({_id, productName, productUnit})=>
<Option key={_id}>{`${productName} (${productUnit})`}</Option>
)
}
</Select>
将商品名称和单位都放入到了 label 中,这样在
check = () => {
this.setState({
editable: false
});
if (this.props.onChange) {
this.props.onChange(this.state.value);
}
};
方法中,通过 onChange 函数,将 value 对象传递回 父组件 AddStorageGrid 中:
onListCellChange(index, key){
const {editProducts} = this.props;
const {totalAmount, paymentAmount} = this.state;
return ({key, label})=> {
const dataSource = [...this.state.dataSource];
const arr = label.match(/([\u4e00-\u9fa5\w]+)/g);
dataSource[index]['productId'] = key;
dataSource[index]['productName'] = arr[0];
dataSource[index]['productUnit'] = arr[1];
this.setState({dataSource});
editProducts(dataSource, totalAmount, paymentAmount);
}
}
这个方法你应该很熟悉啦,箭头函数的参数 {key, label}
就是 value 对象,这时候我需要把 “单位” 提取出来,然后放到表格数据的 ‘productUnit’ 属性中,const arr = label.match(/([\u4e00-\u9fa5\w]+)/g);
这句就是一个正则匹配,如果 label 为 'aa(bb)', 那么匹配出来的 arr = ['aa', 'bb']
,对于字母数字 /([\w]+)/g
足以, 加入 \u4e00-\u9fa5
是为了匹配出汉字 : )
from accountsystem.
@yvanwangl 谢谢你的解答,因为最近工作比较忙没来得及关issue,如果我还有问题继续沟通哈。
from accountsystem.
@yvanwangl 还有一个问题哦,是StorageList取值的问题,如以下代码:
{
title: '金额',
dataIndex: 'totalAmount',
key: 'totalAmount',
render: (text, record, index)=> numberFormat(text)
},
取totalAmount可以取到,
但是products是Array型的,如果取products里面的值怎么取呢?
from accountsystem.
Related Issues (19)
- npm run start:dev报错了! HOT 1
- npm run start:dev报错是什么原因呢 HOT 1
- 账号密码错误登录失败
- 配置好环境,用guest 123456 登录提示用户名或密码错误 HOT 1
- antd上传文件组件携带cookie
- 登录失效
- demo not working (https://mingdi.yvanwang.com/) HOT 2
- storage.js文件 HOT 1
- 如何创建一个用户 HOT 2
- 求mongo数据库备份
- Local Database needed to import and test HOT 4
- mock 无法访问
- npm run start:dev 上传商品图片报错 HOT 4
- Array取值问题 HOT 1
- 本地发布模式部署 HOT 1
- 在线预览链接无法访问 HOT 2
- 下载后提示 app.model: namespace should be defined HOT 3
- npm install报错 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from accountsystem.