本文概述
- 参数说明
句法:
collection.sync(method, collection, options)
参数说明方法:它代表CRUD操作:创建,读取,更新和删除。
【backbone.js集合sync】集合:它包含用于将数据保存在集合中的一组模型。
options:根据成功的方法,用于显示成功或错误消息。
让我们举个例子。
请参阅以下示例:
<
!DOCTYPE html>
<
head>
<
title>Sync Collection Example<
/title>
<
script src="http://img.readke.com/220416/043K24112-0.jpg" type="text/javascript"><
/script>
<
script src="http://img.readke.com/220416/043K24L0-1.jpg" type="text/javascript"><
/script>
<
script src="http://img.readke.com/220416/043K24144-2.jpg" type="text/javascript"><
/script>
<
/head>
<
body>
<
script type="text/javascript">
//The sync() method reads and fetches the model data
Backbone.sync = function(method, model) {
document.write("The state of the model is:");
document.write("<
br>");
//The 'method' specifies state of the model
document.write(method + ": " + JSON.stringify(model));
};
//The 'myval' is collection instance and contains the values which are to be fetched in the collection
var myval = new Backbone.Collection({
site:"srcmini", title:"A solution of all technology"
});
//The myval.fetch() method display the model's state by delegating the sync() method
myval.fetch();
<
/script>
<
/body>
<
/html>
输出:
将以上代码保存在sync.html文件中,然后在新的浏览器中打开该文件。
文章图片
推荐阅读
- backbone.js集合add
- backbone.js集合tojson
- backbone.js集合初始化
- backbone.js集合模型
- backbone.js集合扩展
- backbone.js模型previousattributes
- backbone.js集合教程
- backbone.js模型previous
- backbone.js模型changedattributes