Created
April 10, 2013 08:29
-
-
Save jayhjkwon/5352834 to your computer and use it in GitHub Desktop.
How to use Knockout.js with CoffeeScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NewsItem | |
constructor : (itemText) -> | |
@content = ko.observable(itemText) | |
class NewsViewModel | |
constructor : -> | |
@items = ko.observableArray() | |
@itemText = ko.observable() | |
addItem : -> | |
@items.push new NewsItem @itemText() | |
$ -> | |
ko.applyBindings new NewsViewModel | |
return |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Document</title> | |
<script src="components/jquery/jquery.js"></script> | |
<script src="components/knockout/build/output/knockout-latest.js"></script> | |
<script src="index.js"></script> | |
</head> | |
<body> | |
<ul data-bind="foreach: items"> | |
<li data-bind="text: $data.content"></li> | |
</ul> | |
<div> | |
<input type="text" data-bind="value: itemText" /> | |
<button data-bind="click: addItem">Add Item</button> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment