Most of a custom widget’s data will come from the JSON. This data does not need to be explicitly defined in the widget’s view model; knockout mapping will automatically create it.

For any data that doesn’t come through JSON, the observable should be explicitly defined in custom JavaScript. Otherwise, an error will be thrown if a template tries to render the property while it’s undefined. For example, imagine a productName widget that is configured with a productId and uses that productId to look up a product in order to display its name. In this case, the productId can be a property defined via koMapping as it should be returned by the JSON data. The product’s name, on the other hand, is expected to be populated when the product lookup completes, so it needs to be defined in the JavaScript as productName: ko.observable(). Otherwise, when the template is rendered, an error will be thrown because productName is not a valid binding (it would be undefined).


Copyright © 1997, 2016 Oracle and/or its affiliates. All rights reserved. Legal Notices