Javascript 在aurelia中对绑定属性更改调用函数

Javascript 在aurelia中对绑定属性更改调用函数,javascript,typescript,aurelia,aurelia-store,Javascript,Typescript,Aurelia,Aurelia Store,我有这个viewmodel,所有的代码都能正常工作 @connectTo<State>({ selector: (store) => store.state.pipe(pluck('domain')).pipe(pluck('games')), target: 'games', }) @connectTo<State>({ selector: (store) => store.state.pipe(pluck('domain')).pipe(plu

我有这个viewmodel,所有的代码都能正常工作

@connectTo<State>({
  selector: (store) => store.state.pipe(pluck('domain')).pipe(pluck('games')),
  target: 'games',
})
@connectTo<State>({
  selector: (store) => store.state.pipe(pluck('domain')).pipe(pluck('myGames')),
  target: 'myGames',
})
@autoinject()
@customElement('games')
export default class Games {
  private static readonly ADD_TO_MYGAMES = 'addToMyGames';
  @bindable() games: Game[] = [];
  myGames: Game[] = [];

  constructor(
    private readonly store: Store<State>,
  ) {
    store.registerAction(Games.ADD_TO_MYGAMES, myGamesState);
  }

  available(game: Game): boolean {
    console.log("available", game);
    return !!this.myGames.find((i) => _.isEqual(i, game));
  }

  addGame(game: Game) {
    this.store.dispatch(Games.ADD_TO_MYGAMES, game);
  }
}

const myGamesState = async (current: State, game: Game) => {
  console.log(game);
  return produce(current, state => {
    state.domain.myGames.push(game);
  });
}

我应该如何解决这个问题?

我认为您正在执行函数引用。您可能希望使用:
已禁用。call=“可用(游戏)”


请参阅:

而不是disabled.bind是否未禁用。call?@weagle08 disabled不是一个函数它似乎也不会在css类中被调用,因为样式没有改变,而且我有点担心它需要被调用两次。此外,我不知道这将如何工作,因为aurelia怎么知道再次调用它呢?第一次创建列表时,它被调用,当我更新时,它没有被调用,
call
可能是正确的调用,但我一直无法让它工作,是的,我已经阅读了文档,也许你可以提供一个更完整的例子。我没有时间创建一个小的演示应用程序来测试你在这里尝试做什么,对不起。如果我在接下来的几天有时间,但你可以从不同的角度来处理,比如在预绑定步骤中为每场游戏设置可用的标志,或者在添加新游戏时在事件上设置可用的标志。