列表页js
var Bmob = require('../../utils/bmob.js');var that;
Page({
onLoad: function () {
that = this;
},
onShow: function () {
that.loadCategories();
},
loadCategories: function () {
var query = new Bmob.Query('Category');
query.limit(Number.Max_VALUE);
query.find().then(function (categories) {
console.log(categories);
that.setData({
categories: categories
});
});
},
add: function () {
// 跳转添加页面
wx.navigateTo({
url: '../add/add'
});
},
})
可以看到,上面使用了onShow代替了onLoad作为加载请求loadCategories,这是因为考虑到添加完毕后会有返回上页,能和自刷新最新数据。
相应的布局页面
class="item" wx:for="{{categories}}" wx:key="">
class="title" url="../add/add?objectId={{item.objectId}}" open-type="navigate" hover-class="none">{{item.title}}