Home > WeChat Applet > Mini Program Development > Analysis of data data operations and function calls in WeChat applet Page

Analysis of data data operations and function calls in WeChat applet Page

不言
Release: 2018-06-27 16:50:30
Original
1876 people have browsed it

This article mainly introduces the WeChat mini program to explain in detail the data data operations and function calls in Page. Friends who need it can refer to

The WeChat mini program explains in detail the data data operations and function calls in Page. Function call

Page() function is used to register a page. Accepts an object parameter, which specifies the page's initial data, life cycle functions, event handling functions, etc.

//index.js 
<pre code_snippet_id="2049407" snippet_file_name="blog_20161214_1_1145312" name="code" class="javascript">Page({ 
 data: { 
  text: "This is page data.",
  sliderOffset: 0, 
  sliderLeft: 0, 
  state:{ 
     genre:[], 
     genre_index: 0, 
     model:[], 
     model_index: 0, 
     terminalStatus:&#39;&#39;, 
  } 
 }, 
 onLoad: function(options) { 
  // Do some initialize when page load. 
 }, 
 onReady: function() { 
  // Do something when page ready. 
 }, 
 onShow: function() { 
  // Do something when page show. 
 }, 
 onHide: function() { 
  // Do something when page hide. 
 }, 
 onUnload: function() { 
  // Do something when page close. 
 }, 
 onPullDownRefresh: function() { 
  // Do something when pull down. 
 }, 
 onReachBottom: function() { 
  // Do something when page reach bottom. 
 }, 
 // Event handler. 
 viewTap: function () { 
  var p = this.position 
  ball(p, 150) 
  function ball(x, y) { 
   console.log(x,y) 
  } 
 }, 
 customData: { 
  hi: &#39;MINA&#39; 
 } 
})

 

1、设置data数据

setData 函数用于将数据从逻辑层发送到视图层,同时改变对应的 this.data 的值。
注意:
(1)、直接修改 this.data 无效,无法改变页面的状态,还会造成数据不一致。
(2)、单次设置的数据不能超过1024kB,请尽量避免一次设置过多的数据。

setData() 参数格式:接受一个对象,以 key,value 的形式表示将 this.data 中的 key 对应的值改变成 value。其中 key 可以非常灵活,以数据路径的形式给出,如 array[2].message,a.b.c.d,并且不需要在 this.data 中预先定义。

下面设置data中的text和genre_index的值

this.setData({ 
   &#39;state.genre_index&#39;:1, 
   text:&#39;data value&#39; 
})

2、获取data数据

获取data中的text和genre_index值需要使用this

<pre code_snippet_id="2049407" snippet_file_name="blog_20161214_4_5833420" name="code" class="javascript">var gener_index=this.data.state.genre_index
var text=this.data.text

 
3、调用viewTap函数 

在viewTap函数中调用内部的ball函数可以直接调用,如果需要在onReady函数中调用viewTap函数需要使用this。

onReady: function () { 
  this.drawBall() 
 },




Copy after login

The above is the entire content of this article. I hope it will be helpful to everyone’s study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

Use picker to encapsulate the three-level linkage of provinces and municipalities in WeChat mini program

WeChat mini program Method for the program server to obtain user decrypted information

The above is the detailed content of Analysis of data data operations and function calls in WeChat applet Page. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template