菜单是动态从接口里面读取的,但是不知道怎么写 module.exports ,不知道怎么在ajax里面写module.exports
const func = function () {
let $d = {};
$d.opId = Cookie.get('user_id');
$d.tokens = Cookie.get('tokens');
Ajax.ajax({
url: Config.api+"/menu/queryAllMenuList",
method:"post",
data:$d,
//processData: options.method === 'get',
dataType: 'JSON',
}).done((data) => {
return [];
})
};
大家讲道理2017-04-17 16:33:58
The acquired data is assembled into a structure that can be recognized by the antd component. For example, does the dataSource attribute of table recognize an array?
黄舟2017-04-17 16:33:58
Encapsulate ajax into a function, call this function and get the value of ajax.
The rest is a matter of manipulating data.
ajax is asynchronous, so module.exports cannot get the value of ajax.
阿神2017-04-17 16:33:58
Call ajax in the module, set a state, change the value of the state after the callback is successful, and then assemble it into an antd component in render
class Demo extends React.Component {
constructor(){
this.state = {
data: []
}
}
componentWillMount(){
//...
Ajax.ajax({
url: Config.api+"/menu/queryAllMenuList",
method:"post",
data:$d,
//processData: options.method === 'get',
dataType: 'JSON',
}).done((data) => {
this.setState({
data: data
})
})
//....
}
render() {
//使用this.state.data作为数据写antdesign的组件
}
}
export default Demo;