Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to read local data in WeChat Mini Programs

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

The editor of this article introduces in detail "how to read local data in WeChat Mini Programs". The content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to read local data in WeChat Mini Programs" can help you solve your doubts. Let's follow the editor's ideas to learn new knowledge.

WeChat Mini Programs local data reading example

In general, under Mini Program's utils folder, we can write local data in, package it into .js files, provide an interface for exposure, and then read local data. If some processing methods for this data are involved, you can also write the methods, encapsulate them in a .js file, and then call them when needed.

Module.exports = {mtData: mtData, searchmtdata: searchmtdata, usedraw: usedraw} var mt_data = mtData () function searchmtdata (id) {var result for (let I = 0; I < mt_data.list.length) Return result +) {var mt = mt_ data.list [I] if (mt.id = = id) {result = mt}} return result | | {}} function mtData () {var arr = {list: [{id: '1list, MTId:' MT001', status: 'working', Duration: 3, Operator:' tom' IdleReason: 'lunch'}, {id:' 2percent, MTId: 'MT002', status:' Idle', Duration: 7, Operator: 'jerry', IdleReason:' reparied'}, {id: '3percent, MTId:' MT003', status: 'Idle', Duration: 6 Operator: 'tom', IdleReason:' lunch'}, {id: '4percent, MTId:' MT004', status: 'working', Duration: 9, Operator:' jerry', IdleReason: 'reparied'}, {id:' 5percent, MTId: 'MT005', status:' Idle' Duration: 2, Operator: 'tom', IdleReason:' lunch'}, {id: '6percent, MTId:' MT006', status: 'working', Duration: 6, Operator:' jerry', IdleReason: 'reparied'}, {id:' 7percent, MTId: 'MT007' Status: 'Idle', Duration: 1, Operator:' tom', IdleReason: 'lunch'}]} return arr}

As shown in the code snippet above, the local data written by function mtData contains the object List. In addition, there is a function searchmtdata, which loads specific data according to the parameters passed. Next, after the method and data are written, you need to write an exposed API:

Module.exports = {mtData: mtData, searchmtdata: searchmtdata, usedraw: usedraw}

Call the data file on other pages (usually in the js file)

Var fileData = require ('.. /.. / utils/data.js') Page ({data: {showData: fileData.mtData () .list,},})

As in the example above, after a value is assigned in data {}, the showData can be displayed directly in wxml.

After reading this, the article "how to read local data in WeChat Mini Programs" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself to understand it. If you want to know more about related articles, welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report