knockout.js

Knockout JS - Use both static class name as well as data bound class name

自闭症网瘾萝莉.ら 提交于 2019-12-20 14:06:18
问题 Anyone know if I can have an html element with both a static class name as well as a dynamic, data-bound class name using KnockoutJS? Something like this: <span class='staticClassName {{viewModelPropertyValue}}'></span> I realize this isn't ko syntax, I'm just using this syntax to get the point across. 回答1: You can use the css binding to add and remove a class based on the truthiness of a value, but it sounds like your viewModelProperty is the name of a class rather than a boolean. You can

Building a SignalR / Knockout dashboard with guaranteed messaging

风流意气都作罢 提交于 2019-12-20 12:36:29
问题 I'm looking into replacing a monitoring dashboard at our company using real-time messaging. The Old Concept: At our company we have a dashboard that displays the (rather detailed) status of over 700 physical machines, plus added meta-information. It was built about 1,5 years ago by a colleague of mine in ASP.NET Web Forms (which I don't like) to enable dispatchers to coordinate where our technicians should go to fix problems (the machines are located in various geographical locations).

How should I be cleaning up KnockoutJS ViewModels?

浪尽此生 提交于 2019-12-20 12:31:29
问题 I have a single-page app where the user pages through lists of items. Each item, in turn, has a list of items. An observable array is updated with new items from the server retrieved via an AJAX request. This all works fine. Unfortunately after a few pages, the number of operations performed (and the amount of memory used in browsers like FireFox and IE8) keeps going up. I've tracked it down to the fact that elements in my observable array are not being cleaned up properly and are actually

Initialize Knockout observable from element attribute value

為{幸葍}努か 提交于 2019-12-20 12:04:48
问题 I have an element that possesses an attribute whose value is bound to a knockout observable: <text transform='matrix(1 0 0 1 1 1)' data-bind='attr:{transform:textTransform}'></text> When the element loads I'd like the observable to contain the value defined on the dom element, however it instead loads as undefined and the attribute is removed from the dom element alltogether: <text data-bind='attr:{transform:textTransform}'></text> Is it possible to initialize the value of a knockout

How to access the index of an item in knockout.js template

拟墨画扇 提交于 2019-12-20 11:53:22
问题 Within my template in tbody below, how can I access the index of the item being rendered? <table> <tbody data-bind="foreach:contacts"> <tr class="contactRow" valign="top"> <td><a href="#" data-bind="click: function(){viewModel.removeContact($data)}">Delete</td> <td><input data-bind="value: FirstName" name="Contacts[].FirstName"/></td> <td><input data-bind="value: LastName" name= "Contacts[].LastName" /></td> <td><input data-bind="value: Username" name="Contacts[].Username"/></td> <td><input

Knockout.js carraige return in paragraph text

女生的网名这么多〃 提交于 2019-12-20 11:09:30
问题 Using knockout.js, how do I include a carriage return in the text that is bound to the text attribute of a paragraph <p> element. In my ViewModel I generated a string of text that is bound to the <p> in the View. I want to include carriage returns in the string which the browser displays with the line breaks. Including <br /> or Environment.NewLine in the string does not seem to work. 回答1: You can use the html binding. JS: function AppViewModel() { this.firstName = "Bert<br\>Test"; this

The simplest example of Knockback js working with a RESTful webservice such as ServiceStack?

梦想的初衷 提交于 2019-12-20 10:48:12
问题 I am looking for a VERY simple example that shows wiring up Knockback code to a backbone model that connects via RESTful service. I am using ServiceStack|c# backend. All of the links below are too complicated and use localStore rather than a RESTful service via url. I also prefer to see examples in Javascript not CoffeeScript. My example url is something like localhost/entities where hitting this will cause the RESTful webservice to return all of the entities. Hitting it with localhost/entity

KnockoutJS: Adding Observable Properties and Functions to objects in a mapping generated ObservableArray

人盡茶涼 提交于 2019-12-20 10:28:26
问题 I'm new to KnockoutJS, and I'm stuck trying to add additional properties and methods to the generated objects in the ko.observableArray() as created by the mapping plugin. Here's where I'm up to: I have a JSON array of Users I've created the ko.observableArray() with the mapping plugin I've got a template that creates table row for each User , so far so good :o) Here's what I'm trying to do: Each User has a property called 'IsActive' - I'd like to data-bind a click event to a method on each

How to use indexOf in KnockoutJS

江枫思渺然 提交于 2019-12-20 10:18:20
问题 All the examples I see of using the IndexOf() method in KnockoutJS are of basic string types. What I want to know is how to return the index of a array that is an object, based on one of the object variables. 回答1: An observableArray exposes a method called indexOf , which is a wrapper to ko.utils.arrayIndexOf that simply loops through the array looking for the item that you pass to it. So, if you have the item you can do: var viewModel = { items: ko.observableArray([{id: 1, name: "one"}, {id

Weird redirect using data-bind submit, sammy.js and knockout.js together

筅森魡賤 提交于 2019-12-20 09:54:25
问题 I have a form like this on my page: <form data-bind="submit: AddFolder"></form> If I have this code in my JS script (of course I've removed all of the unrelated code and tested to make sure I can still recreate with only this code, normally you'll have more code inside here like .get and .post functions): Sammy(function() { }).run(); When the form is submitted, the page redirects to a weird URL like ?ko_unique=1 If I remove the Sammy part from my script, this doesn't happen. I think it has