knockoutjs select change event gets fired when binding

匿名 (未验证) 提交于 2019-12-03 03:10:03

问题:

I have this knockout code: http://jsfiddle.net/nickbuus/Rwabt/

The problem is that whenever the dropdown select box gets filled the change event gets called:

How do I fix this ?

回答1:

There was a lot of broken and unused code in there

http://jsfiddle.net/Rwabt/5/

This one is corrected. What actually did make it call change is for two reasons, you used string in the food model and numbers in category model ("1" != 1), Id 2 was not present in the categories (Only 1) the beer category was set for both food items (CatId 2). Since KO could not find these in the options list it reseted the selected value to null.

That said please have a look at my fiddle to see a more KO way of doing things



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!