Ali low code engine | lowcodeengine – how to configure and call requests

Time:2022-5-7

Starting inLanguage bird document @ blueju

preface

Sending requests is a very important and common part of the front-end. Naturally, Alibaba low code engine will not lack this part.
In Alibaba low code engine, the request is configured in the data source. The location of the data source is shown in the figure below:
Ali low code engine | lowcodeengine - how to configure and call requests

to configure

The configuration interface is shown in the figure below:
Ali low code engine | lowcodeengine - how to configure and call requests
Among them, the data source ID recommends the small hump naming method, because the final returned result of the request will be stored inthis. state. Data source IDAs shown in the figure above, when we expect to display the request results in the table, we canthis. state. Data source IDBind to the table data configuration.

The remaining configuration items are either simple to configure (such as request address, request parameters, automatic request or request method), or they are used less and unnecessary (such as adding data processing function, request header information and timeout duration). This article is not a guide to the use of Alibaba low code engine, so it will not be described in detail.

call

Although there is an item in the request configuration item called whether to automatically request, our real scenario is generally to call the request method by ourselves, such as sending the request when clicking query, clearing the query form and sending the query request when clicking reset

How to call this part is difficult to understand from the user interface, and there is little description in the document. However, if you have experience, you can find a solution by peeling the cocoon and pulling the silk.
Now the demand is to send a query request when clicking the query button. Let’s print this first in the query after clicking the query button, as shown in the figure:
Ali low code engine | lowcodeengine - how to configure and call requests
We already know that the configuration request is in the data source, so we can find some keywords about the data source from the printed this. As shown in the figure above, we find that there is a sub attribute tabledatasource in the attribute datasourcemap, which is consistent with the data source ID in our configuration, and there is a load method below it. I guess it is the calling method, Then we write the calling code in the query method triggered by the query button.

search() {
  console.log(this)
  const response = this.dataSourceMap.tableDataSource.load()
  response.then(res => {
    console.log(res)
    this.setState({
      tableDataSource: res
    })
  })
}

As shown in the figure below, we manually invoked the request as expected and successfully returned the response result.
Ali low code engine | lowcodeengine - how to configure and call requests
Ali low code engine | lowcodeengine - how to configure and call requests