用special控制多ablitity实例中,打开多个ability后调这个方法会关闭掉其他的ability?

如题:用special控制多ablitity实例中,打开多个ability后调这个方法会关闭掉其他的ability?

阅读 584
1 个回答

解决措施您好,可以看下是否是demo的问题,在设置map的时候,每次的key都是一样的,所以map始终只有一个对象,所以每次只能关一个,可以在注册时加一个id区分,如下:ViewModel中:

export class ViewModel {
  showData: Test = { left: [] }
  id:string
  constructor(id:string) {
    this.id = id
    this.showData.left.push(new CloseFile())
    Commands.register(ViewModel.regi(this.id))
  }

  static regi(id:string):Map<string, CloseFileType> {
    console.log('demoTest => 创建')
    let map:Map<string, CloseFileType> = new Map<string, CloseFileType>()
    let close:CloseFileType = new CloseFileModel()
    map.set('closeFile'+ id, close)
    return map
  }
}

Commands中:

export class Commands {
  static CommandsMap: Map<string, CloseFileType> = new Map<string, CloseFileType>()

  static register(map: Map<string, CloseFileType>) {
    console.log('demoTest => ' + '注册' + map.size)
    console.log("demotest => set之前" + Commands.CommandsMap.size)
    map.forEach((value: CloseFileType, key: string) => {
      Commands.CommandsMap.set(key, value)
      console.log('demoTest => ' + key)
    })
    console.log("demotest => set之前" + Commands.CommandsMap.size)
  }

  static execute(id:string) {
    const command = Commands.CommandsMap.get('closeFile'+ id)


    if (!command) {
      return ''
    }

    return command.click()
  }
}
//CloseFile中的excute也加上id:
export class CloseFile {
  click(id:string) {
    Commands.execute(id)
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题