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.
  • 相关阅读:
    js判断值是否为数字
    人脸识别 python调用face++ 功能测试
    【转载】Cesium基础使用介绍
    数据分析R&Python-Rpy2包环境配置
    VR/AR软件—Mirra测试(截至2017/11/13),使AR/VR创作更加便捷
    Cesium左右立体视觉续篇——遗留问题(渲染错误)以及临时替代方案
    在CesiumVR基础上实现3D左右立体视觉
    关于css样式的选择问题
    圣杯布局和双飞翼布局
    冒泡排序法
  • 原文地址:https://www.cnblogs.com/maqunjing/p/3242451.html
Copyright © 2011-2022 走看看