zoukankan      html  css  js  c++  java
  • backbone collection add 事件回调参数

    this.listenTo(this.collection, 'add', this.renderBook);
    
    renderBook: function (item) {
            var bookView = new app.BookView({
                model: item
            });
            this.$el.append(bookView.render().el);
    }

    当我们给collection添加一个model的时候,如果绑定了collection的add事件,那么该事件的回调函数会接收三个参数。

    第一个参数是:当前被add到collection的model对象;

    第二个参数是:当前collection对象。

    第三个参数是可选项,具体是什么官方也没有介绍。

    其它的事件回调类似。以下附上官方事件列表。

    • "add" (model, collection, options) — when a model is added to a collection.
    • "remove" (model, collection, options) — when a model is removed from a collection.
    • "reset" (collection, options) — when the collection's entire contents have been replaced.
    • "sort" (collection, options) — when the collection has been re-sorted.
    • "change" (model, options) — when a model's attributes have changed.
    • "change:[attribute]" (model, value, options) — when a specific attribute has been updated.
    • "destroy" (model, collection, options) — when a model is destroyed.
    • "request" (model, xhr, options) — when a model (or collection) has started a request to the server.
    • "sync" (model, resp, options) — when a model (or collection) has been successfully synced with the server.
    • "error" (model, xhr, options) — when a model's save call fails on the server.
    • "invalid" (model, error, options) — when a model's validation fails on the client.
    • "route:[name]" (params) — Fired by the router when a specific route is matched.
    • "route" (router, route, params) — Fired by history (or router) when any route has been matched.
    • "all" — this special event fires for any triggered event, passing the event name as the first argument.
  • 相关阅读:
    springboot集成mockito与powermock
    不一样的go语言-玩转语法之二
    不一样的go语言-玩转语法之一
    不一样的go语言-athens源码概览
    不一样的go语言-athens私仓安装
    不一样的go语言-构建系统与构件系统
    不一样的go语言-error
    不一样的go语言-gopher
    jssip中文开发文档(完整版)
    echarts属性的设置(完整大全)
  • 原文地址:https://www.cnblogs.com/maqunjing/p/3242451.html
Copyright © 2011-2022 走看看