


Detailed introduction to data data operations and function calls in WeChat applet Page
This article mainly introduces the WeChat mini program to explain in detail the data data operations and function calls in Page. Friends in need 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:'', } }, 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: 'MINA' } })
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({ 'state.genre_index':1, text:'data value' })
2、获取data数据
获取data中的text和genre_index值需要使用this
<pre class="brush:php;toolbar:false">var gener_index=this.data.state.genre_index
var text=this.data.text3、调用viewTap函数
在viewTap函数中调用内部的ball函数可以直接调用,如果需要在onReady函数中调用viewTap函数需要使用this。
onReady: function () { this.drawBall() },
The above is the detailed content of Detailed introduction to data data operations and function calls in WeChat applet Page. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Zend Studio 13.0.1
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Mac version
God-level code editing software (SublimeText3)

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft