ko.observablearray

Knockout observableArray in TypeScript

橙三吉。 提交于 2019-12-03 14:08:20
What is the proper way to initialize a Knockout observableArray in a TypeScript class? I am doing something like this: module ViewModel { declare var ko; export class IndexPageViewModel { agencies: any; constructor () { this.agencies = ko.observableArray([]); } } } var ivm = new ViewModel.IndexPageViewModel(); ivm.agencies.push({name: "name", alias : "alias"}); for (var i = 0; i < ivm.agencies.length; i++){ alert(ivm.agencies[i].name); } Looks simple enough, but when I attempt to access the agencies property as indicated, execution hangs. Did I miss something? This line is where your mistake

Replace all elements in Knockout.js observableArray

允我心安 提交于 2019-12-03 09:19:11
I have an observableArray in my view model. After creating the vm I wish to completely replace the data the observableArray . Here's how I'm doing it: //Initial Setup var vm = {}; vm.roles = ko.observableArray([]); ko.applyBindings(vm); //....replace array later on.... vm.roles(["1", "2"]); This seems to be working fine, but I was concerned if this was incorrect and might lead to memory leaks. Can anyone conform if this is the preferred way to update an existing observableArray assuming you wish to replace all its data? I noticed observableArray does have a removeAll() method and wondered if

Replacing item in observableArray

心已入冬 提交于 2019-12-03 04:45:55
问题 I'm trying to replace all of the contents of an item in an observableArray with new content. var oldLocation = ko.utils.arrayFirst(self.locations(), function (item) { return item.id == value.id; }); self.locations.replace(self.locations.indexOf(oldLocation), new location(value)); self.locations.valueHasMutated(); I've also tried self.locations[self.locations.indexOf(location)] = new fizi.ko.models.location(value); But nothing is working. The index is being properly retrieved but the update of

Replacing item in observableArray

痞子三分冷 提交于 2019-12-02 19:05:51
I'm trying to replace all of the contents of an item in an observableArray with new content. var oldLocation = ko.utils.arrayFirst(self.locations(), function (item) { return item.id == value.id; }); self.locations.replace(self.locations.indexOf(oldLocation), new location(value)); self.locations.valueHasMutated(); I've also tried self.locations[self.locations.indexOf(location)] = new fizi.ko.models.location(value); But nothing is working. The index is being properly retrieved but the update of the item isn't happening. The replace function accepts two parameters, the item you want to replace

Can not properly bind observableArray of observables

梦想与她 提交于 2019-12-02 12:03:47
问题 I have the following code which should bind observableArray of observables. <button data-bind="click: loadTag">Upload</button> <span data-bind="foreach: langs"> <input data-bind="value: $data, valueUpdate: 'afterkeydown'"/> </span> <div data-bind = "text: ko.toJS(langs)"> function vm() { var self = this; this.langs = ko.observableArray([]); this.initiate = function(){ self.langs = ko.observableArray([]); for (var i = 0; i < 4; i++){ self.langs.push(ko.observable('start')); } } this.initiate()

Knockoutjs Recurring Array

纵然是瞬间 提交于 2019-12-02 12:00:28
问题 I am creating a treeview styled object using KnockoutJS and need to be able to have x number of children folders and items. Has anyone done a recurring array on screen, I usually use foreach and I can put one child within another but I can't figure out how to change the template to make them recurring, is it even possible? To clarify I can get the items into knockout fine it's simply getting them displayed on screen. Looked everywhere on the internet but can only find nested templates rather

Knockoutjs Recurring Array

耗尽温柔 提交于 2019-12-02 08:22:43
I am creating a treeview styled object using KnockoutJS and need to be able to have x number of children folders and items. Has anyone done a recurring array on screen, I usually use foreach and I can put one child within another but I can't figure out how to change the template to make them recurring, is it even possible? To clarify I can get the items into knockout fine it's simply getting them displayed on screen. Looked everywhere on the internet but can only find nested templates rather than recurring ones. Can anyone help? Muhammad Raheel Let me demonstrate how you can achieve this using

Can not properly bind observableArray of observables

这一生的挚爱 提交于 2019-12-02 06:12:45
I have the following code which should bind observableArray of observables. <button data-bind="click: loadTag">Upload</button> <span data-bind="foreach: langs"> <input data-bind="value: $data, valueUpdate: 'afterkeydown'"/> </span> <div data-bind = "text: ko.toJS(langs)"> function vm() { var self = this; this.langs = ko.observableArray([]); this.initiate = function(){ self.langs = ko.observableArray([]); for (var i = 0; i < 4; i++){ self.langs.push(ko.observable('start')); } } this.initiate(); this.loadTag = function(){ for (var i = 0; i < 4; i++){ self.langs()[i](i); } } } ko.applyBindings

How to create a computed observable array in Knockout

 ̄綄美尐妖づ 提交于 2019-12-01 02:03:34
I would like to know how to create a computed observable array. In my view model, I have 2 observable arrays, and I would like to have a computed observable array that is simply both arrays combined. function ViewModel() { var self = this; self.listA= ko.observableArray([]); self.listB = ko.observableArray([]); self.masterList= //combine both list A and B This will combine the two arrays and return the combined list. However, it is not a computed observable array (don't know if that is even possible), but a regular computed observable. self.masterList = ko.computed(function() { return this

How to create a computed observable array in Knockout

我们两清 提交于 2019-11-30 21:22:51
问题 I would like to know how to create a computed observable array. In my view model, I have 2 observable arrays, and I would like to have a computed observable array that is simply both arrays combined. function ViewModel() { var self = this; self.listA= ko.observableArray([]); self.listB = ko.observableArray([]); self.masterList= //combine both list A and B 回答1: This will combine the two arrays and return the combined list. However, it is not a computed observable array (don't know if that is