javascript - Knockout ViewModel observable variable combine with computed -


i'm playing around knockout.js data-binding quite long time. but, got stuck problem. actually, enhancement i'm trying do.

now i'm trying this,

  • i've observable variable in vm
  • i've math equation each observable variable
  • every time model updated, before reach view, variable should computed equation , set result on view.

currently, i'm taking 3 variable job done.

var variable = 'x01';  //vm - object of view model. vm[variable] = ko.observable(24.8); vm["+variable+"_conversion"] = "x * 10 - 248";  vm[""+variable+"_computed"] = ko.computed(function() {     val_ac = vm[variable]();     ac = vm[""+variable+"_conversion"];     var x = val_ac;     return eval(ac); },vm); 

to update model:

vm[variable] = 25; 

since, views custom handlers. i'mr eading data below:

value = vm[""+variable+"_computed"](); 

but, here im using 2 variables (though second 1 not hold data function). how can merge above 3 variables one?

may this;

vm[variable] = ko.computed(function(x){     var ac="x * 10 - 276";     return eval(ac); },vm); vm[variable](26);   // --this should set data model , trigger observers  val = vm[variable]; // --this should data set view 

any other better possibilities or improvement suggestions welcome !

edit: adding fiddle link

my question in above link follows:

  • var1, var2 variable holders
  • var1_computed, var2_computed computed holders

how can use 1 set of variables (var1,var2 / var1_computed,var2_computed) both data holder , computations , avoid multiple variables.

it may not make difference in fiddle example. application logic handles 1600 variables, updated @ 10 sec interval. so, should vary careful memory consumption.


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -