<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="seajs/sea.js"></script>
<style>
span{display: block;}
#container ul li{list-style-type: none;float: left;padding: 10px; margin-right: 10px;margin-bottom: 10px;}
#container ul li img{display: block;width: 100px;height: 150px;}
#container ul li p{white-space: nowrap;overflow: hidden; width: 100px;text-overflow: ellipsis;}
</style>
</head>
<body>
<div id="container">
<ul></ul>
</div> <!-- template -->
<script type="text/html" id="book-view">
<span class="books">
<img src="<%= image %>" alt="<%= title %>">
<p><a href="<%= alt %>"><%= title %></a></p>
</span>
</script>
<script>
seajs.config({
base: '../example-3',
alias: {
'jquery': 'lib/jquery-latest.js',
'underscore': 'lib/underscore.js',
'backbone': 'lib/backbone.js',
'DemoModel': 'js/DemoModel',
'DemoView': 'js/DemoView',
'DemoCollection': 'js/DemoCollection',
'DemoApp': 'js/DemoApp'
}
}); seajs.use('DemoApp', function (DemoApp) {
new DemoApp();
});
</script>
</body>
</html>
define('DemoModel', ['jquery', 'underscore', 'backbone'], function (require, exports, module) {
'use strict'; var DemoModel = Backbone.Model.extend({
defaults: function () {
return {
id: '',
alt: '',
url: '',
title: '',
image: ''
}
}
}); module.exports = DemoModel;
});
define('DemoCollection', ['jquery', 'underscore', 'backbone', 'DemoModel'], function (require, exports, module) {
'use strict';
var DemoModel = require('DemoModel'); var DemoCollection = Backbone.Collection.extend({
model: DemoModel,
url: 'https://api.douban.com/v2/book/search?q=javascript',
parse: function (response) {
return response.books;
},
sync: function (method, model, options) {
var params = _.extend({
type: 'GET',
dataType: 'jsonp',
url: this.url,
processData: false
}, options);
return $.ajax(params);
}
}); module.exports = DemoCollection;
})
define('DemoView', ['jquery', 'underscore', 'backbone'], function (require, exports, module) {
'use strict'; var DemoView = Backbone.View.extend({
tagName: 'li',
template: _.template($('#book-view').html()),
render: function () {
this.$el.html(this.template(this.model.toJSON()));
return this;
}
}); module.exports = DemoView;
});
define('DemoApp', ['jquery', 'underscore', 'backbone', 'DemoView', 'DemoCollection'], function (require, exports, module) {
'use strict';
var DemoCollection = require('DemoCollection'),
DemoView = require('DemoView'); var demoCollection = new DemoCollection(); var DemoApp = Backbone.View.extend({
el: 'body',
events: { },
initialize: function () {
var that = this;
this.listenTo(demoCollection, 'reset', this.render);
demoCollection.fetch({
success: function (e) {
console.log('data');
that.render();
},
error: function (e) {
console.log('Something went wrong!');
}
});
},
render: function () {
demoCollection.each(this.addOne, this);
},
addOne: function (item) {
var view = new DemoView({
model: item
}); $('#container ul').append(view.render().el);
}
}); module.exports = DemoApp;
});

Backbone seajs的更多相关文章

  1. Backbone seajs demo2

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. 第四课:seajs的模块编译_compile过程

    最近比较闲,我就讲下seajs的模块编译_compile过程. 这里紧接着第三课的例子来讲解.首先是a.js的编译 Module.prototype._compile = function() { 1 ...

  3. 构建seajs业务模块之grunt VS spm build

    在最开始,我并不知道grunt可以构建CMD模块.(以下spm指代spm build) 当时正困惑于如何用spm方便的构建业务模块,后来看到@twinstony (感谢@twinstony的分享)使用 ...

  4. seajs+spm之再研究

    好久没有用seajs了,之前对spm也只是一知半解,这些天再次拿起来研究.谈谈我的认识与理解. 声明:本文不适合对seajs完全不了解的同学阅读.对于想知道seajs来龙去脉以及spm相关的同学&qu ...

  5. Seajs demo

    index.html <!doctype html> <html lang="en"> <head> <meta charset=&quo ...

  6. Backbone设计思路和关键源码分析

    一. Backbone的江湖地位: backbone作为一个老牌js框架为大规模前端开发提供了新的开发思路:前端MVC模式,这个模式也是前端开发演变过程中的一个重要里程碑,也为MVVM和Redux等开 ...

  7. Backbone.js 的最佳应用场景有哪些?#zhihu#

    这段时间,想再次了解下backbone js的相关知识,就把一些认为不错的拿过来了: 新版的有道笔记 Web 版(http://note.youdao.com)也使用了 Backbone.就像其他答案 ...

  8. [转]seajs详解

    [转]seajs详解 SeaJS 是一个遵循commonJS规范的javascript模块加载框架,可以实现javascript的模块化开发和模块化加载(kk:模块可按需加载或全部加载). SeaJS ...

  9. seaJs学习笔记2 – seaJs组建库的使用

    原文地址:seaJs学习笔记2 – seaJs组建库的使用 我觉得学习新东西并不是会使用它就够了的,会使用仅仅代表你看懂了,理解了,二不代表你深入了,彻悟了它的精髓. 所以不断的学习将是源源不断. 最 ...

随机推荐

  1. ORM 框架

    1.Dapper 2.Entity Framework(EF) http://www.cnblogs.com/n-pei/archive/2011/09/06/2168433.html

  2. Careercup - Microsoft面试题 - 6314866323226624

    2014-05-11 05:29 题目链接 原题: Design remote controller for me. 题目:设计一个遥控器. 解法:遥控什么?什么遥控?传统的红外线信号吗?我只能随便说 ...

  3. Linux 硬盘分区、分区、删除分区、格式化、挂载、卸载

    Linux 虽然一直都有在玩,但是对硬盘操作确实不是很熟悉今天有空,就整理了下. 1,创建分区 先查看下是否有磁盘没有分区 fdisk -l 其中第一个框和第二个框,是已经分好区的磁盘,第三个硬盘没有 ...

  4. Google Guava学习笔记——基础工具类Splitter的使用

    另一项经常对字符串的操作就是根据指定的分隔符对字符串进行分隔.我们基本上会使用String.split方法: String testString = "Monday,Tuesday,,Thu ...

  5. java 命名代码检查-注解处理器

    命名代码检查 根据 <Java 语言规范( 第 3 版 ) > 中第6.8节的要求, Java 程序命名应当符合下列格式的书写规范: 类 ( 或接口 ) : 符合驼式命名法, 首字母大写. ...

  6. 《我是IT一只小小鸟》读后感

    <我是IT一只小小鸟>读后感 首先,非常感谢我的老师给我推荐了这么一本书,虽然刚开始因为这门课学分太低,所以我对老师布置了字数这么多的作业存在有很大的不满,但在看了这本书后我的不满立马得到 ...

  7. 【BZOJ】【1030】【JSOI2007】文本生成器

    AC自动机/DP Orz ZYF 玛雅快要省选了,赶紧复(xue)习(xi)一下AC自动机…… 其实在AC自动机上DP并没有当初想的那么复杂……就是把DP的转移关系换成了AC自动机上的边而已(不过这题 ...

  8. BZOJ 1088

    真是智商不够, 智商题:.... 假如:第1,2个格子已知,然后根据第二列的情况,就可以把所有满足的情况推出来,又萌萌哒.. 无耻攒字数: #include<stdio.h> using ...

  9. 为现代JavaScript开发做好准备

    今天无论是在浏览器中还是在浏览器外,JavaScript世界正在经历翻天覆地地变化.如果我们谈论脚本加载.客户端的MVC框架.压缩器.AMD.Common.js还有Coffeescript……只会让你 ...

  10. 《暗黑世界GM管理后台系统》部署+功能说明文档

    http://www.9miao.com/product-10-1073.html <暗黑世界GM管理后台系统>部署+功能说明文档 <暗黑世界GM管理后台系统>部署+功能说明文 ...