computed-observable

Custom throttle extender in knockout.js

依然范特西╮ 提交于 2020-01-17 02:50:51
问题 I have an observable that's binded to some input, and sometimes it's value changes too fast, so that the end user does not have time to read it. So I want to restrict the speed of changes in input. But it's not a throttle, because throttle is a bottle neck, and the throttled observable does not change at all while it changes. I want to have a custom throttle, so that the first change applies immediately, and then it might change only after a delay (and of course, each time after a delay it

Force a computed property function to run

瘦欲@ 提交于 2020-01-11 15:18:28
问题 Given a computed property vm.checkedValueCount = ko.computed(function(){ var observables = getCurrentValues(); //an array of ko.observable[] return _.filter(observables, function(v) { return v() }).length; }); suppose getCurrentValues() can return different sets of observables which are modified elsewhere in the code (and comes from a more complex structure than an observableArray). I need checkedValueCount to update whenever one of its dependencies change getCurrentValues() returns a

Force a computed property function to run

你离开我真会死。 提交于 2020-01-11 15:18:13
问题 Given a computed property vm.checkedValueCount = ko.computed(function(){ var observables = getCurrentValues(); //an array of ko.observable[] return _.filter(observables, function(v) { return v() }).length; }); suppose getCurrentValues() can return different sets of observables which are modified elsewhere in the code (and comes from a more complex structure than an observableArray). I need checkedValueCount to update whenever one of its dependencies change getCurrentValues() returns a

Computed stops triggering forever if dependency is inside of false branch statement

瘦欲@ 提交于 2020-01-01 16:46:08
问题 I'm faced a problem that my computed observable stops triggering after some sequence of dependency changes. Finally I found out the point: if dependency was inside of false branch statement during latest evaluation, computed will not be triggered next time even if condition became true before evaluation finished . Here is a sample: https://jsfiddle.net/sgs218w0/1/ var viewModel = new function(){ var self = this; self.trigger = ko.observable(true); self.fire = function(){ self.trigger(! self

ko.computed do not fire function upon instantiating

a 夏天 提交于 2019-12-24 03:22:47
问题 Hi is there a way to not fire the function when instantiating a ko.computed example is i have this ko.computed ko.computed(function(){ alert(this.Test); } , this); so basically if i instantiated this computed this will fire the function defined there is there a way not to fire it upon instantiation? and only fire it when dependency change? 回答1: You need to set the deferEvaluation option: deferEvaluation — Optional. If this option is true , then the value of the computed observable will not be

Bind knockout.js to a boolean JQuery Mobile flip switch toggle

我的未来我决定 提交于 2019-12-23 02:17:33
问题 i have a boolean value bound to a JQM flip switch toggle, but i'm not able to see it reacting to changes to the underlying observable. This is my true/false observable: ko.booleanObservable = function (initialValue) { var _actual = ko.observable(initialValue); var result = ko.computed({ read: function () { var readValue = _actual().toString(); return readValue; }, write: function (newValue) { var parsedValue = (newValue === "true"); _actual(parsedValue); } }); return result; }; Which is the

Cannot write a value to a ko.computed unless you specify a 'write' option

房东的猫 提交于 2019-12-22 04:33:29
问题 I am trying to use computed properties in another computed properties and when i run code i am getting following error in console. Cannot write a value to a ko.computed unless you specify a 'write' option function AppViewModel() { var self = this; self.firstName = ko.observable('rahul'); self.lastName = ko.observable('sharma'); self.fullName = ko.computed(function() { return self.firstName() +' ' + self.lastName(); }); self.upperFullName = ko.computed(function() { return self.fullName

How to masked an input text box which is data-bound to Knockout computed variable

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-14 02:48:48
问题 I am using jquery MASKED INPUT PLUGIN for masking my input boxes which are data-binded to knockout variables. I have problem in masking if the knockout variable is Computed Variable. Here is the Fiddler Link https://jsfiddle.net/himanshudhiman/2h1f18qo/5/ I am able to mask input boxes of observable array. But I don't get masking option for the input box of Computed Variable(i.e here in my code is "self.SelectById()"). ViewModel function KeyValuePairOfIdAndName(Name, ID) { var self = this;

How to calculate a total in a grid with breeze.js extended entities?

旧街凉风 提交于 2019-12-13 00:54:57
问题 I am working on an MVC web application using the MVVM pattern, breeze.js and knockout.js. This is the first time I use these js libraries and I still have to grasp how they work. One of the pages of the application has a grid where both columns and rows are generated dynamically. I need to add an additional column where for each row I have the total of values displayed in the following row cells. Here an example: Data type | Comment | Fact 1 | Fact 2 | Total | Value 1 | Value 2 | Value 3 |

Kendo DataSource: How to define “Computed” Properties for data read from remote odata source

為{幸葍}努か 提交于 2019-12-12 07:28:20
问题 Situation: kendo DataSource var ordersDataSource = new kendo.data.DataSource({ type: "odata", transport: { read: { url: "http://localhost/odata.svc/Orders?$expand=OrderDetails" } }, schema: { type: "json", data: function(response){ return response.value; } total: function(response){ return response['odata.count']; } }, serverPaging: true, serverFiltering: true, serverSorting: true }) the json data read from the odata source is like: { odata.metadata: "xxxx", odata.count: "5", value: [ {