// Learn cc.Class: const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey; cc.Class({ extends: cc.Component, properties: { item: cc.Prefab, content: cc.Node }, // LIFE-CYCLE CALLBACKS: // onLoad () {}, start () { }, init(content) { if (this._shops != undefined) { return; } this._content = content; this._shops = {}; let contentWidth = this.content.width; let itemWith = Math.floor((contentWidth - 75) / 2); this._items = [] content.getShopsByType(3).then( (respondData) => { this._shops = respondData.shops; for (let i = 0; i < this._shops.length; ++ i) { let coinItem = cc.instantiate(this.item); let coinItemWidth = coinItem.width; let coinItemHeight = coinItem.height; let radio = coinItemHeight / coinItemWidth; coinItem.width = itemWith; coinItem.height = coinItemHeight * radio; coinItem.getComponent('StoreSmallItem').init(this._shops[i], 3, i); this.content.addChild(coinItem); this._items.push(coinItem); } }).catch((code, msg) => { console.log(code, msg); }) GameEvent.on(GameNotificationKey.GameShowNotificationKey, this, this.updateData); }, updateData() { this._content.getShopsByType(3).then( (respondData) => { this._shops = respondData.shops; for (let i = 0; i < this._items.length; ++ i) { let item = this._items[i].getComponent('StoreSmallItem'); item._shopData = this._shops[i]; item.updateTime(); } }).catch((code, msg) => { console.log(code, msg); }) }, onDestroy() { GameEvent.off(GameNotificationKey.GameShowNotificationKey, this); }, // update (dt) {}, });