KnockoutJS: Tracking menu clicks

后端 未结 1 844
北海茫月
北海茫月 2021-01-24 16:36

I have just started playing with KnockoutJS and it it fascinating. I successfully created some templates to render two panels of an interface with \"ul\" nested menus inside.

相关标签:
1条回答
  • 2021-01-24 16:57

    Your issue is that your variable viewModel is defined in the jQuery ready function, so the functions in your data-binds can't see it, since it is not at the global scope. Even, doing a var viewModel = {} outside the $(function() { ... }); would work.

    The way that you defined your click function looks good to me. Your visible logic though should use viewModel.menuActive() and viewModel.currentMenu() to access the values as they are in an expression.

    Hope this helps. Would be happy to help further, if you get stuck.

    0 讨论(0)
提交回复
热议问题