Knock Outs – What Are Knock Out Options

Best Binary Options Brokers 2020:
  • Binarium
    Binarium

    Top Binary Options Broker 2020!
    Perfect For Beginners and Middle-Leveled Traders!
    Free Education How To Trade!
    Free Demo Account!
    Big Sign-up Bonus!

  • Binomo
    Binomo

    Good Choice For Experienced Traders!

No way to stop bindings #41

Comments

Copy link Quote reply

ghost commented Jan 28, 2020

For first – very great and powerful project!

As i wrote on forum
http://groups.google.com/group/knockoutjs/browse_thread/thread/4fec7a12fb945752
now no way to stop bindings.
It means, that we never can unbind our viewModel or replace it with another, without element recreation.
I think that will be great if we have some method to stop bindings similar to applyBindings, may be ko.stopBindings(rootNode), or place dynamic method on viewModel.
As i see, main problem that when we create *observables in code – we doesn’t get ref to this objects, and bindings bind events to element without way to unbind self created events. So may be we need mirror of ‘init’ – ‘destroy’ method to bindings?

While i’m develop on long living client application, and some times must have reuse DOM elements strategy – this is main issue for me, ’cause now it impossible.
I want to know – what you think about this functional? I can try implement this.

This comment has been minimized.

Copy link Quote reply

thelinuxlich commented Jan 28, 2020

See if my patch can help you:

This comment has been minimized.

Copy link Quote reply

ghost commented Jan 28, 2020

Thanks. No, i needed in correct unbinding.
Now it is impossible, so knockdown doesn’t good choise for me.

This comment has been minimized.

Copy link Quote reply

SteveSanderson commented Feb 8, 2020

We’ve had a few discussions about this – it’s not a trivial thing to implement – it means changing all the existing bindings so they contain “dispose” methods to unhook all the event handlers they attached. Anyone who has implemented custom bindings would have to update them as well.

Best Binary Options Brokers 2020:
  • Binarium
    Binarium

    Top Binary Options Broker 2020!
    Perfect For Beginners and Middle-Leveled Traders!
    Free Education How To Trade!
    Free Demo Account!
    Big Sign-up Bonus!

  • Binomo
    Binomo

    Good Choice For Experienced Traders!

It is a bit of a edge case. Very few people have wanted to do this! However, if people continue to ask for it then it’s likely we’ll do it.

Will consider this after the 1.2.0 release.

This comment has been minimized.

Copy link Quote reply

ghost commented Feb 8, 2020

Thanks for feedback.
I solved my problem, (without knockout) it is better way for me, so it is no more issue for me.
You can close it, if you want.

This comment has been minimized.

Copy link Quote reply

eirikurn commented Apr 23, 2020

I’m interested in support for this. I’m looking at how to combine knockout with a library like jquery.pjax. Will the following situation work properly?

  1. Perform ko.applyBindings(viewModel1, #container)
  2. Later, user clicks link
  3. Replace innerHTML in that #container
  4. Call ko.applyBindings(viewModel2, #container)

Assuming I do not data-bind on the #container element itself, will viewModel1 ceace to affect #container? Should I worry about memory leak?

This comment has been minimized.

Copy link Quote reply

mbest commented Feb 6, 2020

This comment has been minimized.

Copy link Quote reply

AlexDobrushin commented Feb 15, 2020

I have the same issue. But I have to switch view model which is complete different to previous. So I realy need to clean the element, in which I’ve applied binding model and bind in this element a new model.

If I do simply remove element and create new one – I have a memory leak, espessially in IE8.
Is there a way to correctly unbind model from element and remove (or empty) this element without causing memory grown?

This comment has been minimized.

Copy link Quote reply

mbest commented Feb 15, 2020

@AlexDobrushin – Have you tried using an observable view model?

This comment has been minimized.

Copy link Quote reply

mbest commented Feb 16, 2020

@AlexDobrushin – There’s ko.removeNode and ko.cleanNode . The former just calls cleanNode and then removeChild .

This comment has been minimized.

Copy link Quote reply

AlexDobrushin commented Feb 16, 2020

Yes I tried observable model. But the way we did our application it doesn’t work.
My view is a simple
var $div = (‘

Then I need change model and view, what do I do – just the same:
ko.cleanNode($parent);
$parent.empty();
var $div = (‘

template1 and template2 are complex views with bindings of nested templates.

ko.cleanNode is new for me, it helps espessialy in Chrome, but IE8 still leaks.

This comment has been minimized.

Copy link Quote reply

rmeschian commented Dec 12, 2020

Definitely need a way to cleanup bindings. Other than this really serious issue which causes memory leaks, the lib is awesome.

This comment has been minimized.

Copy link Quote reply

fasikk commented Sep 22, 2020

We need to have a way to stop binding.

This comment has been minimized.

Copy link Quote reply

mbest commented Mar 19, 2020

#724 also includes a lot of discussion on this topic.

This comment has been minimized.

Copy link Quote reply

iratherscribble commented Jul 23, 2020

A use case for this need would be having a dropdown list where a user selects a Model and then on selection of the Model, the ViewModel and View is created on the fly. Think of this in the context of not viewing a collection of a single Model, but allowing a user to create new content by selecting the type of content from a dropdown list and having the form fields created for that type of content.

In my case, I have a single ViewModel function and the names and number of properties that are available on that ViewModel is created dynamically. The template and types of elements used to display that ViewModel are also created dynamically. I have a template property on the ViewModel referenced by the placeholder div where that property calls a function to dynamically select a generated template to use for display.

I need a way to be able to manually unbind the placeholder div (within the event handler of some other element on the page/the dropdown list of Models) so I can handle the user selecting a new Model, and then create a new instance of the ViewModel and apply the bindings.

I can handle all the logic to implement the behaviors of my application, I just need the unbinding or disposing functionality within Knockout.

This comment has been minimized.

Copy link Quote reply

DesignByOnyx commented Sep 22, 2020

Hello all – I am new to Knockout and really like a whole lot of things about it. The only thing I don’t like about Knockout thus far is the way events are bound using the data-bind attributes. It feels too much like using onclick attributes – which we all abandoned the day we became half-competent developers.

I understand (and really like) the advantages of viewmodels vs. “controllers”. I don’t want to get into a discussion over the difference between the two, but suffice it to say that binding events from the viewmodel (via. addEventListener() or jQuery.on() ) starts to muddy the water and bring a little “controller” action into viewmodels.

However, I would really love a way to bind events from the viewmodel in such a way that all events were tracked during instantiation and properly unbound during disposal. Another MV* framework I have used solved this problem by allowing something like this:

I’m not trying to say that this is how Knockout should do it (although it would be nice ;) – I just want to show how this problem is solved by another library. The above code handles all hyperlink clicks and all mouseover events on anything with the “button” class. The events are delegated to the #container element – meaning there is only one click event, even if you have a thousand hyperlinks. When the controller gets destroyed or if the #container element is removed from the DOM, all events are unbound.

The Knockout Method is my New Favourite Photoshop Technique

No matter how long you have been a Photoshop user, there are always new tips and tricks to learn! I recently came across a new technique that has transformed the way I work. This method doesn’t use any new tools, in fact I’m pretty sure the feature has been a part of Photoshop for over a decade, yet I only discovered it recently. The feature is an Advanced Blending option within the Layer Styles window named ‘Knockout’. As its name suggests, it ‘knocks-out’ the contents of a particular layer from the layers below. Read on to find out how this feature works, and how I now use it as a replacement to Layer Masks or Clipping Masks in some design scenarios.

This document structure provides a great example of how the Knockout feature works. You have a background photograph, a solid colour banner, then a text element on top. The goal is to ‘punch-out’ the text from the banner to allow the background photo to show through.

Double-click the text layer to open the Layer Style window. In the main Blending Options settings, you will see the menu for Knockout, with three options of None, Shallow, and Deep. Choose Shallow for now.

The knockout effect won’t be visible until the contents of the layer are hidden. This can be done by changing to a blending mode that renders the pixels invisible (ie. Multiply for white text), or by simply reducing the Fill to 0%.

The outline of the text is now ‘knocked out’ of not only the black banner directly underneath, but also any other layers until it reaches the Background layer.

The difference between the Shallow and Deep Knockout options is when contained within a Group, the Shallow option will only knock-out any layers within the same group, whereas Deep will knock-out all layers regardless of layer grouping.

One huge benefit to this knockout method when used with text is the effect is automatically updates whenever the text element is edited.

The technique I previously used to create this effect made use of a Layer Mask. This method lacks the ability to edit the text after it has been filled within the mask. It is also difficult to apply several knockout layers with the option of removing just one, without having to rebuild the entire effect.

Example Usage: Easily add texture effects

My favourite use of Knockout is to apply texturing effects to my artwork, without using a Layer Mask. This method allows you to easily overlay several texture layers to either pick and choose between them, or layer up multiple textures at once. You can see this in action within my free Ink Stamp Texturizer download.

Get Drop down event inside a for each loop using knock out

Here is the sample Code I need to show the customer details in the Pages. I am showing Customer Details not as a single Record in the UI. For each Customer I am trying to Show details in the table. In the Each Customer table i need to display the Pagination. Below is the Sample Code used for displaying the Each Customer. For Pagination I have previous Button a drop Down and a Next Button. Since when the drop down value is changed i need to show the next set for that particular Customer. Problem is i am not able to get the Dropdown event in knock out in the for each loop.

1 Answer 1

If I understand correctly, you need to update your customer details list when the select list value changes. Using the value binding on the select list with an observable property and subscribing to that observable should give you a way to capture the dropdown change and load new data in your view model.

Not the answer you’re looking for? Browse other questions tagged knockout.js or ask your own question.

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

site design / logo © 2020 Stack Exchange Inc; user contributions licensed under cc by-sa 4.0 with attribution required. rev 2020.4.7.36546

Best Binary Options Brokers 2020:
  • Binarium
    Binarium

    Top Binary Options Broker 2020!
    Perfect For Beginners and Middle-Leveled Traders!
    Free Education How To Trade!
    Free Demo Account!
    Big Sign-up Bonus!

  • Binomo
    Binomo

    Good Choice For Experienced Traders!

Like this post? Please share to your friends:
Binary Options Trading, Strategies and Robots
Leave a Reply

;-) :| :x :twisted: :smile: :shock: :sad: :roll: :razz: :oops: :o :mrgreen: :lol: :idea: :grin: :evil: :cry: :cool: :arrow: :???: :?: :!: