deft使用指南:
deftjs的功能是可以帮助SenchaTouch实现真正的mvc。
sencha本来的controller并不是真正的一个view对应一个controller而是很多js合成一个组,放在一起,作为一个controller。任何函数都可以放在一个controller如果你愿意的话,而且在项目的开始,所有的controller都会被加载,这样会严重的影响项目启动的时间。
使用deftjs可以对项目直接进行一个controller绑定一个view,在view被实例化时,controller随之被启用。
本篇内容是按照deft官网安装deft.js之后的使用方法。
1.Deft.mvc.ViewController
这是新的deft中的controller,可以完全取代以前sencha的controller。
我们只要将以前的controller改成这样的:
Ext.define(‘app.controller.MainPageController’,{//app.controller的意思是controller还是放在app/controller中比较好。
extend:'Deft.mvc.ViewController’,//这里将继承的方式改变一下
config:{//这是配置选项,view代表的就是所对应的app/view下的视图,通过这个设置,可以直接调用this.getView()获得这个视图
view:’app.view.MainPage'
},
control:{
MainTabButton:{//这是你的itemid或者ID
tap:'onMainTabButtonTap'
}
/*
<span style="white-space:pre"> </span>虽然这里可以实现这个视图的初始化函数(如果我下面还写了对这个函数的实现的话)但是测试表示,在这里实现视图(最外面的组件)的事件的时候,视图的事件可以发生,但是会影响到你其他的事件的发生,我测试得到其他的事件都无法发生。所以不建议把这些函数写在这里,建议直接写在app/view中的js文件中
view:{
initialize:'onViewInitialize'
}*/
},
onMainTabButtonTap:function(button,e,eOpts){
if(!button.tabview){
if(!Ext.getCmp('MainTab'))
button.tabview = Ext.create(‘app.view.MainTab');
button.tabview = Ext.getCmp('MainTab');
this.getView().add(button.tabview);
}
this.getView().setActiveItem(button.maintab);
}
});
然后将在view里面,添加一个controller:’app.controller.MainPageController
‘即可。(不是在config里面哦,在和requires同一层)
其他的功能我还在探索中。会有更新。
探索完了。。
千万别用deftjs谁用谁哭