Skip to content

Instantly share code, notes, and snippets.

@msarchet
Created January 24, 2012 01:45
Show Gist options
  • Save msarchet/1667273 to your computer and use it in GitHub Desktop.
Save msarchet/1667273 to your computer and use it in GitHub Desktop.
streamfire
function streamInfo(stream) {
var self = this;
self.name = stream.name;
};
function getStream(streamName){
return [{name: streamName}];
}
function getStreams(){
var streams = ko.observableArray();
streams.push(new streamInfo());
streams.push(new StreamInfo(getStream("Day9Tv")));
return streams;
}
function StreamViewModel() {
var self = this;
self.streams = [{name: "LiquidRet"},{name: "Day9Tv"}];
self.favoriteStreams = ko.observableArray(new StreamInfo(self.streams[0]));
self.addFavorite = function(streamName) {
self.FavoriteStreams.push(new StreamInfo(getStream(streamName)));
};
};
ko.applyBindings(new StreamViewModel());
<h2>Your Streams</h2>
<div data-bind="text: favoriteStreams.length"></div>
<table data-bind="visible: favoriteStreams.length() > 2">
<thead>
<tr>
<th>Stream</th>
<th>Favorite</th>
</tr>
</thead>
<tbody data-bind='foreach: favoriteStreams'>
<tr>
<td data-bind='text: name'></td>
</tr>
</tbody>
</table>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment