Get the App
SLTechnology News&Howtos  ›  Development  › 

How does WeChat Mini Programs develop the function of moments?

Shulou Source: shulou.com Published: 2022-06-01 05:49:19 09月29日 Update

The knowledge of this article "how WeChat Mini Programs develops the function of moments" is not quite understood by most people, so the editor summarizes the following contents for you. The content is detailed, the steps are clear, and it has a certain reference value. I hope you can get something after reading this article. Let's take a look at this article "how WeChat Mini Programs develops the function of moments".

First, the analysis of development function: 1. Each piece of content is displayed in a list.

two。 Click to show the details of the content

3. Comment function

Second, the database is set up here with the list and details, we use one table to implement, and the comments use the second table. Total 2 tables

1.post table

We can directly import a JSON like this, but because the information on the front page is operated in this way, the data are all exactly the same. This time, we use cloud functions to collect data to the database on a regular basis.

two。 Collect data

Data structure address:

Var url = 'https://apiquan.ithome.com/api/post?categoryid=0&type=0&orderTime=1526981875455&visistCount=&pageLength='

If you import manually, you can import this data structure:

{"id": 266716, "t": "can ordinary Unicom card be transferred to rice noodle card?" , "c": "[chats]", "cn": "talk freely", "uid": 100058, "un": "China Rocket Army", "rn": "Nokia Lumia 930,930," pt": "/ Date (1527057744773) /", "rt": "/ Date (1527060538403) /", "vc": 0, "rc": 17, "IC": false, "IH": false, "ot": "/ Date (- 6213556800000) /"} Cloud function to obtain URL data code:

Function onRequest (request, response, modules) {var http = modules.oHttp;var url = 'https://apiquan.ithome.com/api/post?categoryid=0&type=0&orderTime=1526981875455&visistCount=&pageLength='http(url, function (error, res, body) {response.end (body);});} Click the test to see the result

In this way, you can get the target URL data. How to insert into the database, see the following code:

Db.insert ({"table": "XXX", / / table name "data": {"a": "XXXX", "b": "XXXX"} / / data to be updated in the format of JSON}, function (err,data) {/ / callback function}). If you insert a single row of data in batch, you can use the following code:

Function onRequest (request, response, modules) {var http = modules.oHttp;var db = modules.oData;var url = 'https://apiquan.ithome.com/api/post?categoryid=0&type=0&orderTime=1526981875455&visistCount=&pageLength='http(url, function (error, res, body) {/ / result is converted to object type var results = JSON.parse (body); var arr = [] / update data for (var i in results) {newdata = {"method": "post", "path": "/ 1/classes/post", "body": results [I]}; arr.push (newdata)} / / get array objects var bat = modules.oBatch;// batch operation bat.exec ({"data": {"requests": arr}}, function (err, data) {/ / callback function response.end (data); return;}) Response.end (JSON.stringify (results.length));});} click test

The above is about the content of this article "how to develop the function of moments by WeChat Mini Programs". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.

Tags: Data content function development function friend program code database object data structure article knowledge article structure result URL information update test Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL NVidia macOS Shulou Tech Info Apple