javascript - ant design 菜单从接口里面获取 怎么写?现在都是写死的
ringa_lee
ringa_lee 2017-04-17 16:31:58
0
3
336

菜单是动态从接口里面读取的,但是不知道怎么写 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 [];
  })
};

ringa_lee
ringa_lee

ringa_lee

reply all(3)
大家讲道理

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?

黄舟

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.

阿神

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;
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template