我需要从执行提取调用的react native中的另一个页面返回函数的结果.我使用如下方法.据我所知,这是因为异步调用.有没有一种特殊的方法可以在本机中实现这一点?
fetchcall.js
import address from '../actions/address'
const dashboard = {
getvals(){
return fetch(address.dashboardStats(),
{method: "POST",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify( {...
}),
})
.then((response) => response.json())
.then((responseData) => {
console.warn(responseData);
return responseData;
})
.catch((error) => { console.warn(error); })
.done();
// return 'test_val'';
}
}
export default dashboard;
Run Code Online (Sandbox Code Playgroud)
dashboard.js
import dashboard from '../../services/dashboard';
class Dashboard extends Component {
componentDidMount(){
console.warn(dashboard.getvals());
}
}
export default connect(mapStateToProps, bindAction)(Dashboard);
Run Code Online (Sandbox Code Playgroud)
它将结果显示为"未定义",但该提取调用有效并显示结果.有什么建议吗?
我需要向onSelectAntD Select 组件的方法传递一个附加参数,该参数无法在选项对象数组中列出。我试图通过映射数组来在 UI 上渲染多个 Select 组件,并且需要将渲染元素的索引传递到onSelect方法中。根据文档,它仅支持 readvalue和optionsfromonSelect方法。有什么解决办法吗?
当前代码:
list.map(input, index) -> {
return <Select
.....
onChange={handleOnChange}
/>
}
handelOnChange = (value, options) => {
.....
}
Run Code Online (Sandbox Code Playgroud)
预期代码:
list.map(input, index) -> {
return <Select
.....
onChange={handleOnChange(index)}
/>
}
Run Code Online (Sandbox Code Playgroud)