1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| import * as Fuse from "../libs/fuse";
const {ccclass, property} = cc._decorator;
@ccclass export default class Game extends cc.Component {
@property(cc.Label) label: cc.Label = null;
@property text: string = 'hello';
start () { this.label.string = this.text; console.log("cc.assetManager->", cc.assetManager);
this.testSearchCharacter(); }
private testSearchCharacter(){ console.log("testHandler"); type Character = { name: string; skill: string; level: number; };
const characters: Character[] = [ { name: "Li Lei", skill: "Fireball", level: 5 }, { name: "Fireball Lei", skill: "Fireball", level: 5 }, { name: "Han Meimei", skill: "Ice Blast", level: 8 }, { name: "Xiao Ming", skill: "Thunder Strike", level: 10 }, { name: "Wang Wei", skill: "Healing Light", level: 6 } ];
const options = { keys: ["name", "skill"], threshold: 0.3 };
const fuse = new (Fuse as any)(characters, options); this.searchCharacter("Fire",fuse); }
private searchCharacter(query: string,fuse) { const results = fuse.search(query); console.log("smile:🚀 ~ f:", JSON.stringify(results)); console.log("搜索结果:", results.map(result => result.item)); } }
|