本文概述
Backbone.js访存模型通过委派模型中的sync()方法从服务器接收数据。
句法:
model.fetch(options)
参数说明
options:指定用于模型的参数,例如id,name等。
让我们举个例子。
请参阅以下示例:
<!DOCTYPE html>
<head>
<title> Fetch Example</title>
<script src="https://code.jquery.com/jquery-2.1.3.min.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.2/underscore-min.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min.js" type="text/javascript"></script>
<script type="text/javascript">
Backbone.sync = function(method, model) {
document.write(method + ": " + JSON.stringify(model));
};
var person = new Backbone.Model({
Country:"India", Name:"APJ Abdul Kalam"
});
person.fetch();
</script>
</body>
</html>
输出:
将上面的代码保存在fetch.html文件中,然后在新的浏览器中打开该文件。
评论前必须登录!
注册