Knockout dirty flag event

天大地大妈咪最大 提交于 2019-12-25 06:36:27

问题


I've used the Dirty Flag Blog post here Knockmeout to implement such a flag in my model, but i can not get this to work properly. Somehow the flag is never set to true.

Additionaly i want my subscribe event to be triggered every time the dirty flag is set to true. (i'll to the reset manually).

Here's a fiddle that shows my issue.

Can someone point me in the right direction?


回答1:


A couple of small things:

  • when you use span tags they should not be self-closing (so do <span></span>). This was preventing your final binding from being shown.
  • if you create your view model inside of an object literal, then this does not yet refer to the view model, so when you created your dirty flag it was not properly tracking your Filter object. If you want to do an object literal, then you would want to create your dirty flag afterwards.
  • the value binding when used with a select will populate your model value with a string. So, I changed your 1 to '1', otherwise it would be dirty immediately. There is a way to force it to be numeric using a writeable computed observable. Here is one technique.

Here is an updated sample: http://jsfiddle.net/rniemeyer/xw76d/4/



来源:https://stackoverflow.com/questions/10896244/knockout-dirty-flag-event

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