Created
October 22, 2013 18:27
-
-
Save tikluganguly/7105511 to your computer and use it in GitHub Desktop.
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 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> |
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
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