knockout.js

KnockoutJS observableArray to update when inner observable is changed

最后都变了- 提交于 2019-12-13 13:09:23
问题 I need to know how to trigger the update for an observableArray when an observable is changed inside the observableArray . I have an observableArray that represents a binary tree. I'm using a storage mapping function to get and set the values in the array so it has to be balance even thought it might only contain an empty observable . E.g. nodes()[9] maybe null but when that node is updated I would call nodes()[9](set new value) and need to trigger the observableArray to update 回答1: Ended up

ko.utils.arrayFirst always returns null when not handling else block with non-empty string

怎甘沉沦 提交于 2019-12-13 13:01:53
问题 This works correctly: self.getById = function(id) { return ko.utils.arrayFirst(self.PostArray(), function(item) { if (item.postId === id) { return item; } else { return 'not found'; } }); }; console.log(self.PostArray().length); console.log(self.getById(170)); But if I put return '' or return null in else block I always get null, why is that? 回答1: You're not using arrayFirst correctly. arrayFirst expects a function that returns true or false , evaluating each item. The first item for which

How to bind knockout checkbox to a material design lite?

≡放荡痞女 提交于 2019-12-13 12:37:44
问题 I am having problems in bind a Knockout array with Material Design Lite checkbox. Basically it doesn't show the checkbox checked. How can that be fixed? var ViewModel = function() { this.uniqueTabsNames = ko.observableArray(['one', 'two', 'three']); } ko.applyBindings(new ViewModel()); <link href="https://fonts.googleapis.com/css?family=Roboto:regular,bold,italic,thin,light,bolditalic,black,medium&lang=en" rel="stylesheet" /> <link href="https://cdnjs.cloudflare.com/ajax/libs/material-design

Knockoutjs. How to compute data changed inside observable array

别说谁变了你拦得住时间么 提交于 2019-12-13 12:27:01
问题 Please, look at my text. I try to use observableArray of knockoutjs and foreach to compute data of array. Example 1 works fine: total sum computed if you change data in the fields. But Example 2 is not working. <html> <head> <title></title> <script type='text/javascript' src='/js/jquery-1.8.2.min.js'></script> <script type='text/javascript' src='/js/knockout-2.1.0.debug.js'></script> </head> <body> <p>Example 1</p> <div> <p> <input data-bind="value: fnum1" /> <input data-bind="value: fnum2" /

AJAX - Sending knockout observables as JSON object to server using AJAX

不打扰是莪最后的温柔 提交于 2019-12-13 12:17:10
问题 I am trying to send form fields which are bound to particular observable to my server in the form of JSON object but I receive empty JSON string at server side. I do not want to send the entire view model to accomplish this task. this is the javascript i have so far: $(document).ready(function(){ ko.applyBindings(new AddSubjectKo()); }); function AddSubjectKo() { var self=this; self.name = ko.observable(); self.quiz = ko.observable(); self.ass = ko.observable(); self.oht = ko.observable();

Using Knockout to Filter ViewModel Data Using Multiple Fields/Columns and Controls

余生颓废 提交于 2019-12-13 12:04:38
问题 I'm new to KnockoutJS but am liking it so far. What I'm trying to do is filter my viewmodel's data using multiple fields/columns and controls on the form, but I'm not sure how to do it. Let me (hopefully) explain further. I have a viewmodel observable array of data that is populated with JSON data from a backend database. This collection of data has multiple columns that I'd like to filter on so that the display changes to only display the selected items. I've followed the example using ko

Sum similar keys in an array of objects In javascript

有些话、适合烂在心里 提交于 2019-12-13 11:14:13
问题 I have an array of objects something like the following: - 0: {Id: 0, count1: 5, count2: 10, yearMonth: "201803"} 1: {Id: 0, count1: 10, count2: 0, yearMonth: "201804"} 2: {Id: 1, count1: 900, count2: 200, yearMonth: "201805"} 3: {Id: 0, count1: 10, count2: 0, yearMonth: "201806"} 4: {Id: 1, count1: 100, count2: 100, yearMonth: "201807"} 5: {Id: 1, count1: 100, count2: 2, yearMonth: "201808"} I want to sum similar keys to get Expected output: 1: {Id: 0, count1: 25, count2: 10} 2: {Id: 1,

Knockout.js won't be recognized after using require.js

白昼怎懂夜的黑 提交于 2019-12-13 10:19:51
问题 Calling require.js before knockout.js throws the following message: Uncaught ReferenceError: ko is not defined Assuming I have knockout.js at the very top of the combined file, I have this: <script type="text/javascript" src="/bower_components/requirejs/require.js"></script> <script type="text/javascript"> requirejs.config({ paths: { text: '/bower_components/text/text' }, }); requirejs([ '/bower_components/text/text.js' ]); </script> <script type="text/javascript" src="/js/dist/combined.min

How to add a row on button click?

落花浮王杯 提交于 2019-12-13 08:15:26
问题 in this fiddle there is an add timing button . There is default row having week day dropdown,from time textfield,to time textfield and hospital drop down.Now when I click on the add timing button I want another row having week day dropdown,from time textfield,to time textfield and hospital dropdown. Can any body please tell me how to do that? This is my knockout code var DocSchedule = function (id, day, fromtime, totime, hospital, hospitalId) { this.id = ko.observable(id); this.day = ko

“//” …“ //]]>” appears on the page when “ //<![CDATA[ ” …“//]]>” are used to wrap a JS code

依然范特西╮ 提交于 2019-12-13 07:57:13
问题 I'm trying to add the html5 drag 'n drop upload file on my JSF web page so i had to add this script into it <script type="text/html" id="template-uploads"> //<![CDATA[ <div data-bind="visible: showTotalProgress()"> <div> <span data-bind="text: uploadSpeedFormatted()"></span> <span data-bind="text: timeRemainingFormatted()" style="float: right;"></span> </div> <div class="uploadimage-totalprogress"> <div class="uploadimage-totalprogressbar" style="width: 0%;" data-bind="style: { width: