04.07.2019 Views

frontend-developer-1

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Customize and Create JavaScript<br />

This works well for any data type except arrays. If the observable contains an array<br />

or an object, a regular knockout observable does not trigger updates when values<br />

within the array change.<br />

For this reason ko.observableArray([]) should be used when working with<br />

arrays.<br />

There also are observable functions, which are called “computed<br />

observables” and are created with a call to ko.computed(callback) or<br />

ko.pureComputed(callback).<br />

Magento also includes the knockout plugkn ko-es5. The benefit of ko-es5 is that it<br />

allows the creation of observables that can be read and set like regular properties,<br />

while knockout still tracks the changes under the hood.<br />

You can use the observable’s subscribe method to listen to changes. The<br />

real value of the observable comes out when you bind that to an element in the<br />

template like:<br />

<br />

What common ko bindings are used?<br />

See above section for a list of common ko bindings.<br />

Demonstrate an understanding of ko virtual elements.<br />

Virtual elements are a way to bind a child element without having to insert a node<br />

into the DOM just to specify the binding.<br />

Copyright © 2018, SwiftOtter, Inc.<br />

96

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!