Home >WeChat Applet >Mini Program Development >Analysis of 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 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:'', } }, 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' } })
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 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.text3、调用viewTap函数
在viewTap函数中调用内部的ball函数可以直接调用,如果需要在onReady函数中调用viewTap函数需要使用this。
onReady: function () { this.drawBall() },
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:
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!