Skip to content

Instantly share code, notes, and snippets.

@engineersamuel
Created April 18, 2013 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save engineersamuel/5416676 to your computer and use it in GitHub Desktop.
Save engineersamuel/5416676 to your computer and use it in GitHub Desktop.
Example knockout expressions
<!-- variable (usually a property of the current view model -->
<div data-bind="visible: shouldShowMessage">...</div>
<!-- comparison and conditional -->
The item is <span data-bind="text: price() > 50 ? 'expensive' : 'cheap'"></span>.
<!-- function call and comparison -->
<button data-bind="enable: parseAreaCode(cellphoneNumber()) != '555'">...</button>
<!-- function expression -->
<div data-bind="click: function (data) { myFunction('param1', data) }">...</div>
<!-- object literal (with unquoted and quoted property names) -->
<div data-bind="with: {emotion: 'happy', 'facial-expression': 'smile'}">...</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment