ko.observablearray

Remove an element from observableArray inside another observableArray in knockout

 ̄綄美尐妖づ 提交于 2020-01-05 12:08:21
问题 After finishing knockout tutorial working with lists and collections I decided to go a little bit further to implement two level nesting with knockout. The structure of my ViewModel looks like this: function ViewModel() { this.elements = ko.observableArray([{ id: 1, txt: 'first', el: ko.observableArray(['first', 'second']) },{ id: 2, txt: 'second', el: ko.observableArray(['first', 'third']) },{ id: 3, txt: 'third', el: ko.observableArray(['fourth', 'fifth']) }]); this.remove = function(el){

Knockout.js: clear selection in select element

℡╲_俬逩灬. 提交于 2020-01-02 08:58:25
问题 I need to clear the selection from a <select> element. I've already read such posts as Knockoutjs clear selected value in combobox and have tried the accepted answers, but those solutions don't seem to be working (don't know if something has changed in Knockout 2 since the answer was accepted?). Here's an example view model: var ClearSelectionViewModel = function () { var self = this; self.station = ko.observable(); self.selectedStation = ko.observable(); self.selectedStation.subscribe

replace observableArray with new data

╄→гoц情女王★ 提交于 2019-12-14 02:17:23
问题 I have a viewmodel like AppViewModel = { agent : ko.observableArray([ { name : 'test', age : '23' }]) }; My json data comes like {"agent":[{"name":"john","age":"23"},{"name":"conor","age":"23"}]} for ajaxcall evry 3 sec How to replace the view model with new data I tried success : function(responseData) { var data = ko.toJS(responseData); //AppViewModel.agent.push(data); AppViewModel.agent.replace(agent,data); } but doest work. 回答1: All you have to do is set the observable success : function

two-way binding of a single object in observableArray

*爱你&永不变心* 提交于 2019-12-12 00:45:57
问题 My page is as follows: <button id="add">Add Data</button> <button id="show">show</button> <table> <tr style="vertical-align:top"> <td> <table border="1"> <thead> <tr> <th>Id</th> <th>Name</th> </tr> </thead> <tbody data-bind="foreach: students"> <tr> <td data-bind="text: id"></td> <td> <input type="text" data-bind="value: name" /> </td> <td> <a href="javascript:void(0)" data-bind="click: $root.showData">Select</a> </td> </tr> </tbody> </table> </td> <td> <table id="data"> <tbody data-bind=

Pushing Values Into nested ko.observableArray

十年热恋 提交于 2019-12-12 00:33:59
问题 I want to nest a list of vendors into an existing JSON Payload that I get from the server, based on if the item within the JSON Payload requires a vendor. What I want to end up with is something that looks like this: { "ProductName": "Product123", "RequiredComponents": "CAP 10% H/Vol", "StockCode": "142111411", "RequiredQtyByBom": 4, "QtyUnassignedInWarehouse": 0, "QtyAllocatedInWarehouse": 40, "PCBReference": "442C", "QtyOnOrder": 26, "Vendors": [], "RequireVendor": false }, { "ProductName":

KnockoutJS observableArray with template and foreach

落爺英雄遲暮 提交于 2019-12-11 19:48:48
问题 I'm trying to bind a Knockout observableArray to my UI using a foreach and checkboxes and then create an array based on what is checked. I'm getting this error: Uncaught ReferenceError: Unable to process binding "template: function () . . . ." Here is my HTML: <dl data-bind="template: { name: 'QuarterTemplate', foreach: Quarter, templateOptions: { selections: SelectedQuarters } }"></dl> <script id="QuarterTemplate" type="text/html"> <dd> <label> <input type="checkbox" data-bind="attr: { value

Dependant Observable Array in Knockout JS

我与影子孤独终老i 提交于 2019-12-11 11:05:31
问题 I have started to play around with knockoutjs and do some simple binding/dependant binding. My goal is to have 1 <select> list populated based on the value of another <select> list. Both are being loaded from an ajax call to my asp.net webservice. So I have two <select> lists <select id="make" data-bind="options: availableMakes, value: selectedMake, optionsText: 'text', optionsCaption: 'Choose a make'"></select> <select id="model" data-bind="options: availableModels, value: selectedModel,

Knockout - groupable array

我的梦境 提交于 2019-12-11 04:41:54
问题 From the tutorial, I am trying to understand this promising framework. My question is how to extract some data from an observable array (filter)? I found a similar quesion here : similar question But I don't know how to implement it. here is the test : jsfiddle HTML code: <h2>Your seat reservations (<span data-bind="text: seats().length"></span>)</h2> <h4> Distribution by meal type: <table> <thead> <tr data-bind="foreach: availableMeals"> <th><span data-bind="text: mealName"></span></th> </tr

Knockout JS: indexOf always returns -1?

青春壹個敷衍的年華 提交于 2019-12-11 02:50:24
问题 Background I'm trying to build a gradebook app, mostly as a learning exercise. Currently, I have two models, a student, and an assignment. I decided to store all score-related information inside the student rather than with each assignment. Perhaps there's a better approach. Regardless, I already have the average score for each student, i.e., her grade in the class. I'm now at the point where I want to calculate the average score on each assignment. This is where I run into trouble, as it's

Hasfocus binding issues with Firefox

时光总嘲笑我的痴心妄想 提交于 2019-12-10 15:16:10
问题 I'm working on an app that utilizes an observable array to present an editable table of userID information. The app works fantastic in Chrome, but I'm having issues getting it to work with Firefox. For my purposes, these two browsers are the only ones that I care about for now. I'm using the "click to edit" functionality through the hasfocus binding in knockout, and it works great with Chrome. Whenever the username is selected, it becomes editable, a save button presents itself, and upon