ko.observablearray

knockoutjs ObservableArrays and sort function: UI is not updated

妖精的绣舞 提交于 2019-12-09 12:11:46
问题 In my viewmodel, I have a knockoutjs ObserableArray. Just after I initialized the ViewModel, it binds the data successfully. Then, what I need to do is to sort the collection. $.each(vm.searchResults(), function (i, property) { console.log(property.Name()); }); vm.searchResults().sort(function (a, b) { return a.Name().toLowerCase() > b.Name().toLowerCase() ? 1 : -1; }); $.each(vm.searchResults(), function (i, property) { console.log(property.Name()); }); As you can see, I output the Name of

Replace all elements in Knockout.js observableArray

女生的网名这么多〃 提交于 2019-12-09 07:24:19
问题 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

Why can not I concat data to observable array in knockout

空扰寡人 提交于 2019-12-08 19:35:55
问题 I am trying to add elements from the server to observable array in knockout. Here is my ViewModel: function ArticlesViewModel() { var self = this; this.listOfReports = ko.observableArray([]); self.loadReports = function() { $.get('/router.php', {type: 'getReports'}, function(data){ for (var i = 0, len = data.length; i < len; i++){ self.listOfReports.push(data[i]); } }, 'json'); }; self.loadReports(); }; And it works perfectly. But I know that I can merge two arrays in javascript using concat(

Knockout ObservableArray not updating HTML Foreach

拈花ヽ惹草 提交于 2019-12-08 15:56:14
问题 So I've got an observablearray that works fine, but the UI doesn't update. I've read lots of people running into this TYPE of issue, but I'm not seeing it. So the HTML is <tbody data-bind="foreach: tweets"> <tr> <td> <span data-bind="visible: created_at" class="label label-success">Yup</span> </td> <td><p><b data-bind="text: screen_name"></b></p></td> <td><p><b data-bind="text: id"></b></p></td> <td><p data-bind="text: text"></p></td> <td><p data-bind="text: created_at"></p></td> </tr> <

Binding around 5000 records using knockout

限于喜欢 提交于 2019-12-08 13:59:37
问题 I am trying to show around 5000 records in a web page using knockout observable array, which is taking hell lot of time, Is there any way to handle this without pagination?? please help.. JS code in view model, data is coming via ajax call in gridData source: groupGrid.prototype.updateGrid = function (gridDataSource, groupGridOptions) { var self = this; self.ColumnName(groupGridOption.ColumnNameList); // List of column name available in the data source. self.gridData(gridDataSource); //

KnockoutJS: How to add one observableArray to another?

岁酱吖の 提交于 2019-12-06 12:07:36
问题 I want to add selected options from select element to binding table. The view model has addItem function that add selectedItems array into addedItems array with using ko.utils.arrayPushAll(). But nothing happens when I click on Add button (calls addItem function). How to correctly add one observable array to another? HTML <label>Parameter list</label> <br/> <select multiple="multiple" data-bind="options: items, selectedOptions: selectedItems, optionsText: 'name', optionsValue: 'id'"> </select

Knockout.js: clear selection in select element

纵饮孤独 提交于 2019-12-06 03:13:07
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(function (value) { self.station(value); }); self.stations = ko.observableArray(['CLT', 'PHL', 'PHX', 'PIT']);

Knockout observableArray in TypeScript

谁说胖子不能爱 提交于 2019-12-04 20:34:26
问题 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

KnockoutJS: How to add one observableArray to another?

北城余情 提交于 2019-12-04 15:37:32
I want to add selected options from select element to binding table. The view model has addItem function that add selectedItems array into addedItems array with using ko.utils.arrayPushAll(). But nothing happens when I click on Add button (calls addItem function). How to correctly add one observable array to another? HTML <label>Parameter list</label> <br/> <select multiple="multiple" data-bind="options: items, selectedOptions: selectedItems, optionsText: 'name', optionsValue: 'id'"> </select> <p> <button data-bind="click: addItem, enable: selectedItems().length > 0">Add</button> </p> <label

knockoutjs ObservableArrays and sort function: UI is not updated

ε祈祈猫儿з 提交于 2019-12-03 14:40:31
In my viewmodel, I have a knockoutjs ObserableArray. Just after I initialized the ViewModel, it binds the data successfully. Then, what I need to do is to sort the collection. $.each(vm.searchResults(), function (i, property) { console.log(property.Name()); }); vm.searchResults().sort(function (a, b) { return a.Name().toLowerCase() > b.Name().toLowerCase() ? 1 : -1; }); $.each(vm.searchResults(), function (i, property) { console.log(property.Name()); }); As you can see, I output the Name of the element to the console to see the order before and after the sorting. The sorting works just fine.