📜  BackboneJS-事件

📅  最后修改于: 2020-10-27 03:39:44             🧑  作者: Mango


事件能够绑定对象并触发自定义事件,即,您可以使用我们选择的所需名称来绑定自定义事件。

下表列出了可用于操纵BackboneJS-Events的所有方法-

S.No. Methods & Description
1 on

It binds an event to an object and executes the callback whenever an event is fired.

2 off

It removes callback functions or all events from an object.

3 trigger

It invokes the callback functions for the given events.

4 once

It extends the backbone.Model class while creating your own backbone Model.

5 listenTo

It informs one object to listen to an event on another object.

6 stopListening

It can be used to stop listening to events on the other objects.

7 listenToOnce

It causes the listenTo occur only once before the callback function is being removed.

内置事件目录

BackboneJS允许在您的应用程序中必要时使用全局事件。它包含一些带有参数的内置事件,如下表所示:

S.No. Events & Description
1

“add”(model, collection, options)

It used when a model is added to the collection.

2

“remove”(model, collection, options)

It removes a model from the collection.

3

“reset”(collection, options)

It is used to reset the collection content.

4

“sort”(collection, options)

It is used when a collection needs to resorted.

5

“change”(model, options)

It is used when changes are to be made to a model’s attributes.

6

“change:[attribute]”(model, value, options)

It is used when there is an update in an attribute.

7

“destroy”(model, collection, options)

It fires when the model is destroyed.

8

“request”(model_or_collection, xhr, options)

It is used when a model or a collection starts requesting to the server.

9

“sync”(model_or_collection, resp, options)

It is used when a model or a collection is synced successfully with the server.

10

“error”(model_or_collection, resp, options)

It activates when there is an error in requesting to the server.

11

“invalid”(model, error, options)

When there is a fail in model validation, it returns invalid.

12

“route:[name]”(params)

When there is a specific route match, this event can be used.

13

“route”(route,params)

It is used when there is a match with any route.

14

“route”(router, route, params)

It is used by history when there is a match with any route.

15

“all”

It fires for all the triggered events by the passing event name as the first argument.