<!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. android ViewPaper高度自适应

    tv_btn_web.measure(0, 0);//计算所需的真实宽高 LayoutParams params=vp_btn_menu.getLayoutParams(); params.heigh ...

  2. asp.net中父子页面通过gridview中的按钮事件进行回传值的问题

    这两天写BS程序,遇到父子页面传值的问题,以前没写过web系统,用了几天时间才将问题解决,总结下记录下来: 问题描述: 父页面A中有一个gridview,每行6个列,有5列中均有一个按钮,单击按钮,会 ...

  3. Android:apk文件结构

    Android apk文件,即Android application package文件. 每个要安装到Android平台的应用都要被编译打包为一个单独的文件,后缀名为.apk,其中包含了应用的二进制 ...

  4. js读取屏幕长宽

    网页可见区域宽 document.body.clientWidth 网页可见区域高 document.body.clientHeight 网页可见区域宽(包括边线的宽) document.body.o ...

  5. Beta版软件说明书

    软件使用说明书 一.    软件概述 本软件面向广大简易图片使用者,旨在为用户提供简单方便的不对其他软件产生依赖的截图软件,可以脱机使用. 二.    运行环境 个人电脑,Windows7操作系统,. ...

  6. PF_PACKET在内核的流程

    PF_PACKET在内核的流程   套接字创建 packet_create() --> 赋值packet_ops   接收流程 packet_recvmsg() skb_recv_datagra ...

  7. hdu 3123 GCC 阶乘

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3123 The GNU Compiler Collection (usually shortened t ...

  8. objc swift 混编

    原链接:http://blog.csdn.net/xuanwenchao/article/details/30226823 在xocde6出来我们大部分代码都是用objective-c写的(部分C/C ...

  9. swipejs的使用

    <div id='slider' class='swipe'> <div class="swipe-wrap"> <div><img sr ...

  10. jvm 之 国际酒店 8 月 19 一次full GC 导致的事故

    事故经过: 1  15:18收到短信报警:国际酒店调用OMS queryGorderOrderList方法失败:成单接口调用OMS获取token失败. 2  查看checkList发现15:18开始发 ...