backbone.js集合where

本文概述

  • 参数说明
Backbone.js集合的where方法通过使用集合中的match属性来检索和显示模型。
句法:
collection.where(attribute)

参数说明属性:它指定已定义模型的属性。
让我们以一个示例来部署where方法。
请参阅以下示例:
< !DOCTYPE html> < head> < title>Collection Example< /title> < script src="http://img.readke.com/220416/052Q16463-0.jpg" type="text/javascript">< /script> < script src="http://img.readke.com/220416/052Q14241-1.jpg" type="text/javascript">< /script> < script src="http://img.readke.com/220416/052Q14607-2.jpg" type="text/javascript">< /script> < /head> < body> < script type="text/javascript"> var players = new Backbone.Collection([ {name: "Sachin", job: "Cricketer"}, {name: "Dhoni", job: "Cricketer"}, {name: "Bradman", job: "Cricketer"}, {name: "Ronaldo", job: "Footballer"}, ]); var Cricketer = players.where({job: "Cricketer"}); document.write("Total numbers of items that matches given attribute are:", +Cricketer.length); < /script> < /body> < /html>

输出:
【backbone.js集合where】将以上代码保存在where.html文件中,并在新的浏览器中打开该文件。
backbone.js集合where

文章图片

    推荐阅读