knockout-2.0

How to Clear Contents of an observableArray That was Populated from Previous Visits to a View

别来无恙 提交于 2019-12-03 04:12:51
I have a Single Page Application that uses knockout for the data binding. The CAApproval.html view in my single page application has an observeablearray named AllCertificates in the viewmodel code. It populates fine on the page. When you navigate away from the view by clicking a link in the navigation.html part of the page and then return to CAApproval page, the values from the previouse visit are still in the AllCertificates observableArray and therefore are displayed on the CAApproval view. I need to clear the contents of the AllCertificates observablearray each time a user returns to the

Initialize Knockout observable from element attribute value

随声附和 提交于 2019-12-03 03:06:35
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 observable from a dom element attribute and persist the value of the dom element attribute as well? UPDATE:

Using Knockout to Populate Bootstrap Rows and Spans

浪尽此生 提交于 2019-12-03 00:35:39
Well essentially I'm trying to populate a Bootstrap template via Knockout and a JSON object. Bootstrap scaffolding: <div class="row-fluid"> <div class="span4"> <h1>App Title</h1> <p>App Description</p> </div> <div class="span4"> <h1>App Title</h1> <p>App Description</p> </div> <div class="span4"> <h1>App Title</h1> <p>App Description</p> </div> </div> <div class="row-fluid"> <div class="span4"> <h1>App Title</h1> <p>App Description</p> </div> <div class="span4"> <h1>App Title</h1> <p>App Description</p> </div> <div class="span4"> <h1>App Title</h1> <p>App Description</p> </div> </div> ... Here

Knockout Validation async validators: Is this a bug or am I doing something wrong?

流过昼夜 提交于 2019-12-02 20:34:43
I really like how Eric Barnard's knockout validation lib integrates with observables, allows grouping, & offers custom validator pluggability (including on-the-fly validators). There are a couple of places where it could be more UX flexible/friendly, but overall it's reasonably well-documented... except, imo, when it comes to async validators . I wrestled with this for a few hours today before doing a search and landing on this . I think I have the same issues/questions as the original author, but agree it wasn't clear exactly what duxa was asking for. I want to bring the question more

Knockout checkbox change event sends old value

橙三吉。 提交于 2019-12-02 19:58:52
I'm having a problem with knockout "checked" binding. It seems that "change" event at checkbox return old value, before it is updated(so if it was unchecked it will return false). I don't think that I can subscribe to the value since I have it inside object. <tbody data-bind="foreach: Categories"> <tr> <td><input type="checkbox" data-bind="checked: ShowOpened, event: { change: $root.CategoryChange }" /></td> </tr> </tbody> <script type="text/javascript"> var Category = function (Id, Name, Order, ShowOpened) { this.Id = Id; this.Name = Name; this.Order = Order; this.ShowOpened = ShowOpened;

Knockout JS Ajax call not populating observable array

北战南征 提交于 2019-12-02 02:54:00
问题 The below example shows an observable array being populated from with Json, which then allows you to filter the results into 2 lists based on 'type'. This all works fine until I try and load exactly the same Json from a ajax call! The strange thing is if i put an alert in the script it then works fine... http://jsfiddle.net/spdKE/3/ <h2>Brand</h2> <ul id="list-dimensions" data-bind="foreach: filteredDimensions('BRAND')"> <li> <div class="item">ID</div> <span data-bind="text: $data.id"</span>

How can I get a leaflet.js instance using only a DOM object?

对着背影说爱祢 提交于 2019-11-30 20:42:54
I'm right now building a custom Knockout.js binding to handle drawing of polygons. In this case the Knockout API only gives me a reference to a DOM object to access whatever it is I need to update. However, it looks like by design leaflet.js wants the user to store the map instance in their implementation. I don't have that option. Trying this gave me an error: var existingMap = L.map('aMapIDGoesHere') And the error was: map already initialized . Any way I can use a DOM element or element ID to access the map instance? By request here's the custom binding, please note it's a work in progress:

Formatting Date in Knockout Template

烂漫一生 提交于 2019-11-30 17:49:57
I'm wanting to format a date in knockout's template. The date is currently being returned as 2013-07-04T00:00:00 I would like it to be displayed like 07/04/2013 Here is the binding I'm using <td data-bind="text: FirstDate"> Are their default formatting properties in Knockout's template? nemesv There is nothing built in regarding date formatting or formatting in general in Knockout. The text binding just converts the property value to string so if you want custom formatting you need to do it yourself. Working with dates is not so easy in JavaScript so you are probably better with using a third

Knockout Twitter Bootstrap Popover Binding

爷,独闯天下 提交于 2019-11-30 09:43:43
I am trying to create a custom binding for twitter boostrap popovers that references a template but I am having trouble with the binding part of the content inside of the popover once it has been created. I have seen this question asked before but I feel like they were mostly pretty messy and I am pretty close to a reusable solution that uses templates how I want to. http://jsfiddle.net/billpull/Edptd/ // Bind Twitter Popover ko.bindingHandlers.popover = { init: function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) { var tmplId = ko.utils.unwrapObservable

Setting the id attribute with knockoutjs including a prefix

人走茶凉 提交于 2019-11-30 07:47:41
I'm using KnockoutJS to iterate over an object, like this: Now this all works. But the problem i have is that it sets the id of the button to just a number. So it looks like this: <button id="1">Button 1</button> <button id="3">Button 2</button> <button id="8">Button 3</button> So i tried to put a prefix in front of the the 'Id' property, like so: <div data-bind="foreach:Items"> <button data-bind="text: Name, attr: {'id': 'myprefix_' + Id}"></button> </div> But that doesn't seem to be working. My id gets filled with some Knockout observable function when i do it like that... So my question is,