简体   繁体   English

使用RactiveJS自动检测DOM的更改

[英]Auto Detect change of DOM with RactiveJS

I'm using RactiveJS for making a big form who change values of field automatically. 我正在使用RactiveJS制作大型表单,这些表单会自动更改字段的值。

A little plunkr for example => http://plnkr.co/edit/eONFQFLl6d2g7gdVcfM6?p=preview 例如一个小矮人=> http://plnkr.co/edit/eONFQFLl6d2g7gdVcfM6?p=preview

When I change the first select, the second is updated but the value stay the older. 当我更改第一个选择时,第二个被更新,但该值保持较旧。 On my project, I don't have juste 2 select but maybe ten with a lot of options and changes when we select differents values. 在我的项目中,我没有选择2,但是当我们选择不同值时,可能只有十个选项和更改很多。

It's possible to update automatically all value with actual options ? 是否可以使用实际选项自动更新所有值?

I found a solution. 我找到了解决方案。 Trigger all change events (not just the select input) with jQuery and make a updateModel(). 使用jQuery触发所有更改事件(而不仅仅是select输入),并创建一个updateModel()。

For exemple 举个例子

$('*').on('change', function(){ setTimeout(function(){ ractive.updateModel(); }, 0); });

You can do the same thing with ractive.observe : 您可以使用ractive.observe做同样的事情:

var ractive = new Ractive({
  el: 'container',
  template: '#template',
});

ractive.observe('*', function(){ 
  setTimeout(function(){ ractive.updateModel(); })
});

http://plnkr.co/edit/t4CZRa6FWIdmMQhLqAKo?p=preview http://plnkr.co/edit/t4CZRa6FWIdmMQhLqAKo?p=preview

See http://docs.ractivejs.org/latest/observers for more info on using keypaths and wildcards to tailor your observe. 有关使用键路径和通配符定制观察值的更多信息,请参见http://docs.ractivejs.org/latest/observers

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

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