• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Babyfacer摩羯座
https://github.com/babyfacer0104
博客园    首页    新随笔    联系   管理    订阅  订阅
require.js+backbone.js基本使用

一、菜单
{
//银行卡基础信息维护
rsId: 'menu.param.cardbin',
iconCls: 'icon-double-angle-right',
name: menusLang._('menu.param.cardbin'),
url: '#',
deps: ['app/param/card-bin/card-bin-app'],// app/param/card-bin/list/list-view
trigger: 'card-bins:list'
}

二、第二步
define(['app'],
function(App) {
App.module('CardBinApp', function(CardBinApp) {
var CardBinAppRouter = Marionette.AppRouter.extend({
appRoutes: {
"card-bins(/filter/kw::kw)": "listCardBins"
}
});

/////////////////////////////////////////////////////////////////
// define methods for interaction (with parent app) and router //
/////////////////////////////////////////////////////////////////
var API = {

listCardBins: function(kw) {
console.log('>>>>param-sys.listCardBins ' + (kw || ''));
require(['app/param/card-bin/list/list-controller'], function (ctrl) {
ctrl.listCardBins(kw);
});
}

};

//if it is not used to map the url first time typed in browser
//u can new router anywhere before u want, otherwise, u should
//add router before start Backbone history
new CardBinAppRouter({ controller: API });


/////////////////////////////////////////////////
//register events or command to parent app //////
/////////////////////////////////////////////////
App.on('card-bins:list', function(kw) {
API.listCardBins(kw);
});


//this callback will be invoked before parent app:initilize:after
App.addInitializer(function() {

console.log('>>>>new CardBinAppRouter');

});

});

return App.CardBinApp;

});

三、第三步 controller
define(['app'], function(App) {
App.module('aaa.bbb', function(List, App, Backbone, Marionette, $, _) {
List.Controller = {
listCardBins: function(kw) {
require([''], function(View) {
var xxx = new View.xxxx({});
App.show(xxx);
});
}
};
});
return aaa.bbb.Controller;
});

四、list-view
define(['app'], function(App, paramLang) {
App.module('aaa.bbb.View', function(View, App, Backbone, Marionette, $, _) {
View.xxxx = .....
});
return aaa.bbb.View;
});

posted on 2015-09-02 10:42  Babyfacer摩羯座  阅读(285)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3