本文概述
- 参数说明
句法:
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集合findwhere
- backbone.js集合pluck
- backbone.js集合排序sort
- backbone.js集合比较器comparator
- backbone.js集合length
- backbone.js集合slice
- backbone.js集合shift
- backbone.js集合unshift
- backbone.js集合at