简体   繁体   English

淘汰赛脏旗事件

[英]Knockout dirty flag event

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. 我在Knockmeout的Dirty Flag Blog文章中使用了这样的标记来实现我的模型,但是我无法使其正常工作。 Somehow the flag is never set to true. 不知何故,该标志永远不会设置为true。

Additionaly i want my subscribe event to be triggered every time the dirty flag is set to true. 另外,我希望每次脏标志设置为true时触发我的订阅事件。 (i'll to the reset manually). (我将手动重置)。

Here's a fiddle that shows my issue. 这是一个小提琴 ,显示了我的问题。

Can someone point me in the right direction? 有人可以指出我正确的方向吗?

A couple of small things: 一些小事情:

  • when you use span tags they should not be self-closing (so do <span></span> ). 当您使用span标签时,它们不应自动关闭( <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. 如果您在对象文字内部创建视图模型,则this视图模型尚未引用该视图模型,因此当您创建脏标志时,它无法正确跟踪您的Filter对象。 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. 与select一起使用时,值绑定将使用字符串填充模型值。 So, I changed your 1 to '1' , otherwise it would be dirty immediately. 因此,我将您的1更改为'1' ,否则将立即变脏。 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/ 这是一个更新的示例: http : //jsfiddle.net/rniemeyer/xw76d/4/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM