[Angular 2 Tutorial] Backbone.js Tutorial Part 6 – Backbone.js Collections: Creating Collections [w/ subs]



00:00:02 – [Music]
00:00:12 – to work with a group of models building
00:00:15 – collections is very easy and is similar
00:00:17 – to building models we simply extend back
00:00:20 – bonded collection and specify the type
00:00:22 – of models that the collection can hold
00:00:24 – let's see this in action
00:00:34 – you
00:00:44 – we can put objects in a collection in
00:00:46 – two ways we can pass the initial array
00:00:49 – of models when creating the collection
00:00:50 – or we can call the add method on an
00:00:52 – instantiated collection
00:01:01 – you
00:01:32 – the add method is provided by underscore
00:01:34 – and is available in all background
00:01:36 – collections underscore provides many
00:01:39 – other methods that make working with
00:01:40 – collections really easy we'll cover them
00:01:43 – in a few minutes all right now let's go
00:01:45 – to chrome and inspect our collection
00:01:54 – no this property's here
00:01:58 – these are the ones that are collection
00:02:00 – inherited from the base backbone that
00:02:02 – collection object every backbone
00:02:05 – collection has length and models
00:02:07 – property the length property returns the
00:02:10 – number of models inside the collection
00:02:12 – and the models property gives us direct
00:02:14 – access to these models most often we use
00:02:18 – the add or get methods to access a model
00:02:20 – in the collection let's try them
00:02:24 – the add method returns a model at the
00:02:26 – given index here zero represents the
00:02:29 – first model in the collection also note
00:02:33 – that this model has this CID of c1 every
00:02:37 – backbone model has two its1 is a
00:02:39 – persistent ID which is assigned by the
00:02:41 – server and another one is the client ID
00:02:44 – or CID which is assigned by backbone CID
00:02:48 – is a temporary identifier that backbone
00:02:50 – uses to keep track of objects
00:02:53 – we can get a model from a collection by
00:02:55 – its ID which is leads purchased an ID or
00:02:58 – cid which is a client ID so another way
00:03:02 – for us to get the same model here is
00:03:04 – like this
00:03:10 – we can also remove a model from a
00:03:12 – collection by calling the remove method
00:03:17 – the remove method expects a model so you
00:03:20 – need to get the model by either its
00:03:22 – index or its ID and then pass it to this
00:03:25 – method
00:03:27 – let's verify that the model is removed
00:03:36 – bang bang collections provide an easy
00:03:39 – way to work with a group of models we
00:03:41 – can create a collection type by
00:03:43 – extending back bonded collection we can
00:03:46 – add models to a collection when
00:03:47 – instantiating a collection or by calling
00:03:50 – the add method the length property
00:03:52 – returns the number of models inside the
00:03:55 – collection the add method returns the
00:03:57 – model at the specified index the get
00:04:00 – method returns the model specified by
00:04:03 – its ID or cid we can remove a model from
00:04:07 – a collection by cutting the remove
00:04:08 – method all the methods with car
00:04:12 – [Music]


Video Url:
http://youtu.be/vBSuoZnNOik

Comments

comments