![]() If your parameter references an observable value, the binding will add or remove the CSS class whenever the observable value changes. For example, 0 and null are treated as false, whereas 21 and non- null objects are treated as true. Non-boolean values are interpreted loosely as boolean. It’s merely a shortcut syntax if you want two or more CSS classes to be set and unset together. Logically, 'major highlight': isSevere is equivalent to major: isSevere, highlight: isSevere. For example, if your view model has a property called isSevere, You can set multiple CSS classes at once. You should pass a JavaScript object in which the property names are your CSS classes and their values evaluate to true or false according to whether the class should currently be applied. Knockout will evaluate them and use the resulting value to determine the appropriate CSS classes to add or remove. If the parameter references an observable value, the binding will update the classes whenever the value changes, removing any previously added classes and adding the class or classes from new value.Īs usual, you can use arbitrary JavaScript expressions or functions as parameter values. The parameter value should be a string that corresponds to the CSS class or classes that you want to add to the element. This will apply the CSS class profitWarning whenever the currentProfit value dips below zero, and remove that class whenever it goes above zero. ViewModel.currentProfit(-50) // Causes the "profitWarning" class to be applied Usage with AMD using RequireJs (Asynchronous Module Definition)ĬurrentProfit: ko.observable(150000) // Positive value, so initially we don't apply the "profitWarning" class.Overview: What components and custom elements offer.Preprocessing: Extending the binding syntax.How KO works and what benefits it brings.
0 Comments
Leave a Reply. |