淘汰赛脏旗事件 [英] Knockout dirty flag event

查看:63
本文介绍了淘汰赛脏旗事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在此处使用了肮脏标志博客文章

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.

此外,我希望每次将脏标志设置为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).

这是显示我问题的小提琴.

有人可以指出我正确的方向吗?

Can someone point me in the right direction?

推荐答案

一些小事情:

  • 使用span标记时,它们不应自动关闭(<span></span>也是如此).这阻止了您显示最终的绑定.
  • 如果您在对象文字内部创建视图模型,则this尚未引用该视图模型,因此,当您创建脏标志时,它不能正确跟踪您的Filter对象.如果要执行对象文字,则需要在以后创建脏标志.
  • 值绑定与选择一起使用时,将使用字符串填充模型值.因此,我将您的1更改为'1',否则它将立即变脏.有一种方法可以使用可写的可计算观察值将其强制为数字.这是一个技术.
  • 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.

这是更新后的示例: http://jsfiddle.net/rniemeyer/xw76d/4/

这篇关于淘汰赛脏旗事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆