Reading list Switch to dark mode

    knockoutJs Binding Observables & Magento2

    Updated 23 December 2015

    As Magento2 has been introduced with loads of new tech stacks , knockoutjs is one of those stacks . Magento2 uses ko (we will use ko as knockout) at admin and front end as well specially with their magento2 ui framework .

    KnockoutJS is an open source JavaScript library. It was built to allow you to create
    dynamic and rich web applications. It is built with the Model-View-ViewModel
    (MVVM) pattern.Ko contains mainly Three aspect

    • Model
    • View
    • View Model

    Its kind of MVC where model and view are similar view model is new concept . Will explain what is view model with an example

     

    Start your headless eCommerce
    now.
    Find out More

    as explained in above tutorial , A ViewModel can be any type of JavaScript variable / function .

    ko.applyBindings is  to perform the data binding of the view and the View‐
    Model. This is accomplished by calling the ko.applyBindings function with a View‐
    Model.

    When this function is executed, Knockout processes both the view and the
    ViewModel. All data bindings in the view are executed and dynamically replaced with
    the data from the ViewModel.

    HTML bindings with knockoutjs

    Knockout is also capable of binding html as well as described in the below example

    . . .

    Leave a Comment

    Your email address will not be published. Required fields are marked*


    Be the first to comment.

    Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home