knockout.js

Javascript memory leak when changing model data in KnockoutJS

ぃ、小莉子 提交于 2019-12-21 19:41:16
问题 We're building a fairly large one-page-application with KnockoutJS as "data-handler". The problem is that when changing model-data, the old models isn't disposed by the garbage collector (as it seems). The application has about 12 different models with computed obserables that you can retreive relations with. In the ViewModel I have a observable array for each of the model. Lets say I fill a array with 100 instances of a model. When I later want to change these 100 to 100 different instances

knockout template binding

浪子不回头ぞ 提交于 2019-12-21 17:19:33
问题 I have an ul element which is filled through template binding. <script type="text/html" id="someTemplate"> <li> <span data-bind="text: someText"> </li> </script> <ul data-bind="template: {foreach: someElemets, name: 'someTemplate'}"> </ul> But I want the first li-tag would not be li-tag from template but another one with button in it and it will not be connected to someElemets array. If I do in that way <ul data-bind="template: {foreach: someElemets, name: 'someTemplate'}"> <li><button data

Durandal router / lifecycle events when using a childRouter

旧巷老猫 提交于 2019-12-21 16:55:31
问题 In a single page app built using Durandal, I have a settings view, with different sections. I use a childRouter to resolve the different sections. In this application, a lot of code hooks into the composition lifecycle events that Durandal uses. For example, this custom binding: ko.bindingHandlers.autoFocus = { init: function (element) { var $element = $(element), setFocus = function () { $element.focus(); }; router.on('router:navigation:composition-complete', setFocus); ko.utils

How to open a new tab with router.navigate in TypeScript

守給你的承諾、 提交于 2019-12-21 15:06:08
问题 The following typescript code will always open in the current browser tab navigate($data: menuItem, $event: JQueryEventObject) { //... let a = $event.currentTarget as HTMLAnchorElement; router.navigate(a.href); } How do I make router.navigate open in a new tab ? (that is when $event.ctrlKey is true) 回答1: Yes, as you @Daneille commented, you have to handle by your own way since durandal's router plugin (navigate function) does not provide a way to open a new tab. So it is better to handle

How to open a new tab with router.navigate in TypeScript

こ雲淡風輕ζ 提交于 2019-12-21 15:03:00
问题 The following typescript code will always open in the current browser tab navigate($data: menuItem, $event: JQueryEventObject) { //... let a = $event.currentTarget as HTMLAnchorElement; router.navigate(a.href); } How do I make router.navigate open in a new tab ? (that is when $event.ctrlKey is true) 回答1: Yes, as you @Daneille commented, you have to handle by your own way since durandal's router plugin (navigate function) does not provide a way to open a new tab. So it is better to handle

MVC pass JSON ViewModel to View

淺唱寂寞╮ 提交于 2019-12-21 14:33:30
问题 I have an MVC application that I'm using various JsonResult endpoints to populate the javascript ViewModel. I have been using several jQuery Ajax requests to populate the model, but I'd like as much of the inital model to be passed to the view on the server. The ViewModel has 3-5 pieces (depending on where the user is in the application): Basic page links, these don't change very often and could be the exact same throughout the entire user's session User notifications. User data. (optional)

KnockoutJS proper way to update observableArray AJAX

Deadly 提交于 2019-12-21 12:59:50
问题 In KnockoutJS, what's the proper way to update an observableArray of JSON data each time an AJAX command is run? Right now, I'm blanking the array using something like viewmodel.items([]), then repopulating it with the JSON data from the server. Short of using the KnockoutJS mapping plugin (which might be the only way to do this) what is the correct path? My server logic is going to send some of the same data each time, so I can't just iterate and push the items into the array unless I want

KnockoutJS proper way to update observableArray AJAX

痞子三分冷 提交于 2019-12-21 12:59:25
问题 In KnockoutJS, what's the proper way to update an observableArray of JSON data each time an AJAX command is run? Right now, I'm blanking the array using something like viewmodel.items([]), then repopulating it with the JSON data from the server. Short of using the KnockoutJS mapping plugin (which might be the only way to do this) what is the correct path? My server logic is going to send some of the same data each time, so I can't just iterate and push the items into the array unless I want

Knockout: valueAccessor vs viewModel on custom binding handlers?

时光毁灭记忆、已成空白 提交于 2019-12-21 12:42:04
问题 What's the difference between getting access to a view model's values through the binding properties (via valueAccessor) and getting them from the viewModel argument passed to the handler's init and update? I have always assumed the answer is that those model properties linked to valueAccessor automatically set up bindings (which would fire an update on any change to observables) but I'm not sure about that. 回答1: The valueAccessor argument gives you access to specifically what was passed into

How can I pass the current element to a Javascript function in a Knockout.js binding?

╄→гoц情女王★ 提交于 2019-12-21 12:39:41
问题 So I'm trying to add a class to an element using Knockout.js based on whether a child checkbox is checked or not. To do so, I'm trying to pass this as an argument to my function. Currently, my abridged DOM structure is the following: <tr data-bind="css: { selected: isRowChecked(this) }"> <td><label><input type="checkbox"></label></td> </tr> An my isRowChecked function is this (I'm using jQuery to locate the input): function isRowChecked(elem) { var checkbox = $(elem).find('input[type=