博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
backbone collection add 事件回调参数
阅读量:4599 次
发布时间:2019-06-09

本文共 1600 字,大约阅读时间需要 5 分钟。

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 .
  • "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  call fails on the server.
  • "invalid" (model, error, options) — when a model's  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.

转载于:https://www.cnblogs.com/maqunjing/p/3242451.html

你可能感兴趣的文章
Day4
查看>>
OpenMobile's Application Compatibility Layer (ACL)
查看>>
html中文件类型的accept属性有哪些
查看>>
JS及JQuery对Html内容编码,Html转义
查看>>
Coursera公开课笔记: 斯坦福大学机器学习第十课“应用机器学习的建议(Advice for applying machine learning)”...
查看>>
竞价广告系统-广告检索
查看>>
强哥PHP面向对象学习笔记
查看>>
[转]基于.NET平台常用的框架整理
查看>>
Symbian (Read Inbox)读取收件箱的内容
查看>>
良好的编程规范
查看>>
struts2 入门
查看>>
.net 编译原理
查看>>
mean 快速开发和现有技术的对比分析
查看>>
Metro Style app :浏览器扩展
查看>>
linux的kernel是怎样工作的(TI_DM36X_ARM系统)(1)
查看>>
[luogu4310] 绝世好题 (递推)
查看>>
[luogu3203 HNOI2010] 弹飞绵羊 (分块)
查看>>
-Dmaven.multiModuleProjectDirectory system propery is not set.
查看>>
Python2 unichr() 函数
查看>>
Python 字典 copy()方法
查看>>