knockout.js

Custom throttle extender in knockout.js

依然范特西╮ 提交于 2020-01-17 02:50:51
问题 I have an observable that's binded to some input, and sometimes it's value changes too fast, so that the end user does not have time to read it. So I want to restrict the speed of changes in input. But it's not a throttle, because throttle is a bottle neck, and the throttled observable does not change at all while it changes. I want to have a custom throttle, so that the first change applies immediately, and then it might change only after a delay (and of course, each time after a delay it

Mapping List with Knockout Mapping

左心房为你撑大大i 提交于 2020-01-16 13:18:25
问题 I have created view model var catalog = ko.observableArray(); $.ajax({ type: "GET", url: "http://localhost:8080/ticket-service/rest/ticket/list", success: function(msg) { catalog.push.apply(catalog, $.map(msg, function(data) { return new Ticket(data) })); return catalog; }, error: function(msg) { console.log(msg) } }); and the model function Ticket(data) { this.ticketId = ko.observable(data.ticketId); this.ticketNo = ko.observable(data.ticketNo); this.ticketTitle = ko.observable(data

Typescript Knockout best way to retain 'this'?

人盡茶涼 提交于 2020-01-16 02:56:42
问题 This is an extra question to this TypeScript and Knockout binding to 'this' issue - lambda function needed? where two methods of retaining this inside a Knockout function is proposed: class viewmodelclass { declaredinconstructor: (args) => void; constructor(public someobjects: Array) { this.declaredinconstructor=(args) =>{ } } declaredoutside(args) { } declaredoutsidecorrectly = (args) => { console.log(this); }; } Producing this Javascript: var viewmodelclass = (function () { var _this = this

Can`t get json object to with knockout

无人久伴 提交于 2020-01-16 01:08:06
问题 I can`t get json object. My object is: public class Person { public string firstName { get; set; } public string lastName { get; set; } } PersonsControll: public ActionResult Index() { return View(); } // GET: /Persons/GetPerson //[AcceptVerbs(HttpVerbs.Get)] //[OutputCache(Duration = 0, VaryByParam = "*")] public JsonResult GetPerson() { Person p = new Person { firstName = "Jonas", lastName = "Antanaitis" }; return Json(p, JsonRequestBehavior.AllowGet); } My index view: @Scripts.Render("~

Knockout Performance - Filtering an Observable Array

筅森魡賤 提交于 2020-01-16 00:59:13
问题 I'm new to Knockout, and I'm trying to use it on a page showing a system's users and the roles that each user has. The data is in an observableArray of users. The user object has a roles property, which is another observableArray . This second array contains an object for each role, with an ID and a boolean "granted" property. I want to be able to display all of the users with a specific role, so there's a checkbox for each role - when one of these is checked, the list should show the users

Dynamic composition using knockout and durandal doesn't work

北战南征 提交于 2020-01-16 00:40:26
问题 I have a strange problem while using Durandal/Knockout. In some cases the binding doesn't work properly. I've simplified my situation which came in this question. I'm setting composition info somewhere in my code like: compositionInfo({ model: viewModelInstance, view: viewName, activate: viewModelInstance.activate }); And this is my view: <div id="service-container" data-bind="compose: { model: compositionInfo().model, view: compositionInfo().view, activate: compositionInfo().activate}"> At

Do not allow typing in textarea if it has too many characters

删除回忆录丶 提交于 2020-01-15 19:16:33
问题 I am trying to do the following functionality. Show a number of characters left in the textarea and disallow entering anything else if you already exceeded the maximum number. I am confused with how to achieve this. Now I have something like this: <textarea data-bind="textInput: message"></textarea> <p>Characters left : <span data-bind="text: charLeft"></span></p> function Vm_app() { var self = this; this.message = ko.observable(''); this.charLeft = ko.pureComputed(function(){ return 128 -

Do not allow typing in textarea if it has too many characters

空扰寡人 提交于 2020-01-15 19:16:27
问题 I am trying to do the following functionality. Show a number of characters left in the textarea and disallow entering anything else if you already exceeded the maximum number. I am confused with how to achieve this. Now I have something like this: <textarea data-bind="textInput: message"></textarea> <p>Characters left : <span data-bind="text: charLeft"></span></p> function Vm_app() { var self = this; this.message = ko.observable(''); this.charLeft = ko.pureComputed(function(){ return 128 -

knockout js foreach binding is not updating when used in custom element (components.register)

此生再无相见时 提交于 2020-01-15 12:13:43
问题 ko.components.register("toast-container", { viewModel: ToastViewModel, template: '<div data-bind="foreach: array1"><div data-bind="text:someText"> </div></div>' }); function ToastViewModel(params) { var self = this; self.array1 = ko.observableArray(); self.Onclick = function () { self.array1.push({ someText: "some content" }); } } $(function () { ko.applyBindings(new ToastViewModel()); }); When i push some content in array1 dynamically, the UI is not updating. Please help me. 回答1: Check this:

inserting dynamic html into durandal views

浪子不回头ぞ 提交于 2020-01-15 10:43:28
问题 I am dynamically inserting html in durandal views but it does'nt work can any one help me out in that? my sample html is in durandal view <div data-bind="foreach:arrayofmodels"> <div data-bind="html:dynamichtml"/> </div> in my model(not view model) which is going to insert dynamic html dynamichtml(<span data-bind="click:Mymodelclickfunction"/>); in my viewmodel var arrayofmodels=ko.observableArray(); vm={ arrayofmodels:arrayofmodels; } return vm; there is a separate function to get list of