Skip to content

Instantly share code, notes, and snippets.

@tikluganguly
Created October 22, 2013 18:27
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 tikluganguly/7105511 to your computer and use it in GitHub Desktop.
Save tikluganguly/7105511 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<script src="http://documentcloud.github.io/underscore/underscore-min.js"></script>
<script src="http://documentcloud.github.io/backbone/backbone-min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body ng-controller="Controller1">
<ul>
<li ng-repeat="car in collection.models">
{{ car.name }}
<input type="number" ng-model="car.attributes.cost">
</li>
</ul>
<p>{{ collection.totalCost() | currency }}</p>
</body>
</html>
var data = [
{ id: 1, name: 'Honda', cost: 10 },
{ id: 2, name: 'Toyota', cost: 20 },
{ id: 3, name: 'Ford', cost: 40 }
];
var CarCollection = Backbone.Collection.extend({
totalCost: function() {
var total = 0;
this.forEach(function(model) {
total += model.get('cost');
});
return total;
}
});
function Controller1($scope) {
var collection = new CarCollection(data);
$scope.cars = collection.toJSON();
$scope.collection = collection;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment