<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ## Backbone.Events(事件) **Events** 是一個可以融合到任何對象的模塊, 給予 對象綁定和觸發自定義事件的能力. Events 在綁定之前 不需要聲明, 并且還可以傳遞參數. 比如: ``` var object = {}; _.extend(object, Backbone.Events); object.on("alert", function(msg) { alert("Triggered " + msg); }); object.trigger("alert", "an event"); ``` 舉個例子, 你可以定義一個事件調度程序,然后在你應用的不同地方調用,例如: `var dispatcher = _.clone(Backbone.Events)` **on**`object.on(event, callback, [context])`別名: bind 在 object 上綁定一個**callback**回調函數。 只要**event**觸發,該回調函數就會調用。如果你的一個頁面含有大量的不同時間,我們約定使用冒號來為事件添加 命名空間 俗成地使用冒號來命名:`"poll:start"`, 或 `"change:selection"`。 事件字符串也可能是用空格分隔的多個事件列表(愚人碼頭注:即可以同時綁定多個事件,事件用空格分隔)... ``` book.on("change:title change:author", ...); ``` 當回調函數被調用時,通過可選的第三個參數可以為`this`提供一個**context(上下文)**值:`model.on('change', this.render, this)` (愚人碼頭注:即回調函數中的This,指向傳遞的第三個參數)。 當回調函數被綁定到特殊"all"事件時,任何事件的發生都會觸發該回調函數,回調函數的第一個參數會傳遞該事件的名稱。舉個例子,將一個對象的所有事件代理到另一對象: ``` proxy.on("all", function(eventName) { object.trigger(eventName); }); ``` 所有Backbone事件方法還支持事件映射的語法, 作為可惜的位置參數: ``` book.on({ "change:title": titleView.update, "change:author": authorPane.update, "destroy": bookView.remove }); ``` **off**`object.off([event], [callback], [context])`別名: unbi nd 從 object 對象移除先前綁定的 **callback** 函數。如果沒有指定**context(上下文)**,所有上下文下的這個回調函數將被移除。如果沒有指定callback,所有綁定這個事件回調函數將被移除;如果沒有指定event,所有事件的回調函數會被移除。 ``` // Removes just the `onChange` callback. object.off("change", onChange); // Removes all "change" callbacks. object.off("change"); // Removes the `onChange` callback for all events. object.off(null, onChange); // Removes all callbacks for `context` for all events. object.off(null, null, context); // Removes all callbacks on `object`. object.off(); ``` 需要注意的是,調用 `model.off()`,例如,這確實會刪除model(模型)上_所有_的事件—包括Backbone內部用來統計的事件。 **trigger**`object.trigger(event, [*args])` 觸發給定 **event**或用空格隔開的事件的回調函數。后續傳入 **trigger** 的參數會傳遞到觸發事件的回調函數里。 **once**`object.once(event, callback, [context])` 用法跟[on](#Events-on)很像,區別在于綁定的回調函數觸發一次后就會被移除(愚人碼頭注:只執行一次)。簡單的說就是“下次不在觸發了,用這個方法”。 **listenTo**`object.listenTo(other, event, callback)` 讓 **object** 監聽 **另一個(other)**對象上的一個特定事件。不使用`other.on(event, callback, object)`,而使用這種形式的優點是:**listenTo**允許 **object**來跟蹤這個特定事件,并且以后可以一次性全部移除它們。**callback**總是在**object**上下文環境中被調用。 ``` view.listenTo(model, 'change', view.render); ``` **stopListening**`object.stopListening([other], [event], [callback])` 讓 **object** 停止監聽事件。如果調用不帶參數的**stopListening**,可以移除 **object** 下所有已經[registered(注冊)](#Events-listenTo)的callback函數...,或者只刪除指定對象上明確告知的監聽事件,或者一個刪除指定事件,或者只刪除指定的回調函數。 ``` view.stopListening(); view.stopListening(model); ``` **listenToOnce**`object.listenToOnce(other, event, callback)` 用法跟 [listenTo](#Events-listenTo) 很像,但是事件觸發一次后callback將被移除。 **Catalog of Events(事件目錄)** 下面是Backbone 內置事件的完整列表,帶有參數。 你也可以在Models(模型),Collection(集合),Views(視圖)上自由地觸發這些事件,只要你認為合適。 收藏和意見,你認為合適。 `Backbone` 對象本身混入了`Events`,并且可用于觸發任何全局事件,只要您的應用程序的需要。 * **"add"** (model, collection, options) — 當一個model(模型)被添加到一個collection(集合)時觸發。 * **"remove"** (model, collection, options) — 當一個model(模型)從一個collection(集合)中被刪除時觸發。 * **"reset"** (collection, options) — 當該collection(集合)的全部內容已被替換時觸發。 * **"sort"** (collection, options) — 當該collection(集合)已被重新排序時觸發。 * **"change"** (model, options) — 當一個model(模型)的屬性改變時觸發。 * **"change:[attribute]"** (model, value, options) — 當一個model(模型)的某個特定屬性被更新時觸發。 * **"destroy"** (model, collection, options) —當一個model(模型)被[destroyed(銷毀)](#Model-destroy)時觸發。 * **"request"** (model_or_collection, xhr, options) — 當一個model(模型)或collection(集合)開始發送請求到服務器時觸發。 * **"sync"** (model_or_collection, resp, options) — 當一個model(模型)或collection(集合)成功同步到服務器時觸發。 * **"error"** (model_or_collection, resp, options) — 當一個model(模型)或collection(集合)的請求遠程服務器失敗時觸發。 * **"invalid"** (model, error, options) — 當model(模型)在客戶端 [validation(驗證)](#Model-validate)失敗時觸發。 * **"route:[name]"** (params) — ?當一個特定route(路由)相匹配時通過路由器觸發。 * **"route"** (route, params) — 當_任何一個_route(路由)相匹配時通過路由器觸發。 * **"route"** (router, route, params) — 當_任何一個_route(路由)相匹配時通過history(歷史記錄)觸發。 * **"all"** — 所有事件發生都能觸發這個特別的事件,第一個參數是觸發事件的名稱。 一般來說,事件觸發(例如model.set,collection.add或者其他事件)后就會執行回調函數,但是如果你想阻止回調函數的執行,你可以傳遞{silent: true}作為參數。很多時候,這是一個好的方法。通過在回調函數里傳輸一個特定的判斷參數,會讓你的程序更加出色。 一般而言,事件觸發(`model.set`, `collection.add`,等等...)后就會調用一個函數,但是如果你想阻止事件被觸發, 您可以傳遞`{silent: true}`作為一個選項。注意,這中情況很少, 甚至從來沒有, 一個好主意。 通過在選項中傳遞一個特定的標記,回調函數里傳輸一個特定的判斷參數 并且選擇忽略,會讓你的程序更加出色。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看