我有一个数组定义如下:
selectedDocumentID = [];
Run Code Online (Sandbox Code Playgroud)
接下来,当我获取 ID 时,我有一个函数,以及我将 id 作为参数提供的其他函数。当我点击带有 id 的元素时,这个 id 将进入这个modifyArray。接下来,我使用 console.log 检查 id(它正在工作,我得到了 id)。之后,我创建一个新的数组列表,其中包含 selectedDocument 数组。(这行得通)。我想推送一个 id(如果它不存在)或如果存在(如果存在)将其从列表中切片...
modifyArray(id) {
let selectedDocumentID = [];
let id = 10;
console.log('this is: ' + id);
console.log(this.selectedDocumentID);
let list = this.selectedDocumentID;
let index = list.findIndex( x => x === id);
console.log(index);
if (index !== id) {
list.push(id);
console.log(list);
this.selectedDocumentID = list;
}
else {
list = list.slice(list.indexOf(id));
console.log(list);
this.selectedDocumentID = list;
}
}
Run Code Online (Sandbox Code Playgroud)
例如。我单击 id 为 2,4,5,6 的文档。
我的 selectedDocumentID = …
我在更新子画面时遇到问题。
我创建了一个换衣服的功能。它应该像这样工作:
// Something like this.
pet = pet_with_hat
Run Code Online (Sandbox Code Playgroud)
https://github.com/futer/pandachii上有代码js / main.js的387行。
当我写这个:
this.pet = this.game.add.sprite(90,90, 'pet_black_hat')
Run Code Online (Sandbox Code Playgroud)
发生错误:
Uncaught TypeError:无法读取未定义的属性“运行状况” GameState.update @ main.js:194 Phaser.StateManager.update @ phaser.js:16628 Phaser.Game.update @ phaser.js:23092 Phaser.RequestAnimationFrame.updateRAF @ phaser.js:41421 _onLoop @ phaser.js:41407
如何将此宠物的精灵图像更改为另一个?
我会很感激。