事件能夠結(jié)合對象,并引發(fā)自定義事件即可以使用選擇的所需名稱綁定自定義事件。
下表列出了所有可以用它來操作BackboneJS-事件的方法:
S.N. | 方法及說明 |
---|---|
1 |
on 這一個(gè)事件綁定到一個(gè)對象,并執(zhí)行每當(dāng)一個(gè)事件被觸發(fā)回調(diào)。 |
2 |
off 它消除回調(diào)函數(shù)或來自對象的所有事件。 |
3 |
trigger 它調(diào)用回調(diào)函數(shù)對于給定的事件。 |
4 |
once 它擴(kuò)展backbone.Model類創(chuàng)建自己的backbone模型。 |
5 |
listenTo 它通知一個(gè)對象來監(jiān)聽另一個(gè)對象的事件。 |
6 |
stopListening 它可以用來停止監(jiān)聽到另一對象的事件。 |
7 |
listenToOnce 它會(huì)導(dǎo)致listenTo只發(fā)生在回調(diào)函數(shù)被刪除之前一次。 |
BackboneJS允許使用應(yīng)用程序在必要的全局事件。它包含了一些與參數(shù)內(nèi)置事件下表所示:
S.N. | 事件和說明 |
---|---|
1 |
"add"(model, collection, options) 它用于當(dāng)模型被添加到集合 |
2 |
"remove"(model, collection, options) 它從集合中刪除模型 |
3 |
"reset"(collection, options) 它用于將復(fù)位集合內(nèi)容 |
4 |
"sort"(collection, options) 它是用來采集時(shí)需要重排序 |
5 |
"change"(model, options) 其用于當(dāng)在模型的屬性改變 |
6 |
"change:[attribute]"(model, value, options) 它用于當(dāng)在一個(gè)屬性的更新 |
7 |
"destroy"(model, collection, options) 它觸發(fā)模式時(shí)被銷毀 |
8 |
"request"(model_or_collection, xhr, options) 它用于模型或保藏開始請求到服務(wù)器 |
9 |
"sync"(model_or_collection, resp, options) 它是用來當(dāng)模型或收集與服務(wù)器成功同步 |
10 |
"error"(model_or_collection, resp, options) 它激活時(shí),在請求到服務(wù)器錯(cuò)誤 |
11 |
"invalid"(model, error, options) 當(dāng)在模型驗(yàn)證一個(gè)失敗,則返回?zé)o效 |
12 |
"route:[name]"(params) 當(dāng)有一個(gè)特定路由的匹配,該事件可以被使用 |
13 |
"route"(route,params) 它用于當(dāng)存在與任何路由匹配 |
14 |
"route"(router, route, params) 它使用歷史有一個(gè)與任何路由匹配 |
15 |
"all" 它激發(fā)了傳遞活動(dòng)的名稱作為第一個(gè)參數(shù)都觸發(fā)的事件。 |