开始学习Cocos Creator,现在正在看21点的代码,有个问题
在RankList.js里有代码如下:
const players = require(‘PlayerData’).players;
cc.Class({
extends: cc.Component,
properties: {
scrollView: cc.ScrollView,
prefabRankItem: cc.Prefab,
rankCount: 0
},
// use this for initialization
onLoad: function () {
this.content = this.scrollView.content;
this.populateList();
},
populateList: function() {
for (var i = 0; i < this.rankCount; ++i) {
var playerInfo = players[i];
var item = cc.instantiate(this.prefabRankItem);
item.getComponent('RankItem').init(i, playerInfo);
this.content.addChild(item);
}
},
// called every frame
update: function (dt) {
},
});
很想知道其中 this.content = this.scrollView.content;这句里的this.content是怎么来的?
1、首先这个不是一个省略var的变量
2、这个脚本是绑定在RankList这个空节点里的
如果这个节点是ScrollView,倒是好理解,因为ScrollView里是有content这个属性的,而cc.Component和cc.Class里都没有这个属性,因此产生疑惑
有哪位大神知道的吗?求教
