Home Diary Blog Photo Community Open Source
customize map for small program of wechat
onShow(options) {
let that = this;
var s = wx.getStorageSync('map');
var map;

if (s) {
  console.log('in storage');
  map = s;

} else {
console.log('not in storage');
map = {};

map[1] = { id: 1, name: 'test1' };
map[2] = { id: 2, name: 'test2' };
map[3] = { id: 3, name: 'test3' };
map[5] = { id: 5, name: 'test5' };
map[9] = { id: 9, name: 'test9' };
map[10] = { id: 10, name: 'test10' };
map[12] = { id: 12, name: 'test12' };
}

console.log(map.size);
console.log(map.length);

if (map[3]) {
  console.log('c3 is exist.')
}

if (!map[8]) {
  console.log('c8 is not exist.')
}

delete map[5];

map[10].name='test10000';

for (let key in map) {
  console.log(key);
}

let list = [];
for (let key in map) {
  list.push(map[key]);
}

console.log(JSON.stringify(map));
wx.setStorageSync('map', map);

that.setData({
  list: list,
  map: map,
})
},

<view wx:for="{{list}}" wx:for-item="item" wx:key="*this">
    {{item.id}}  - {{map[item.id].name}}
</view>