我对Sencha touch 2和List Component有疑问。首先,我很抱歉我的英语水平很差。我会努力做到最好。
好吧,我有一个里面有一个列表组件的视图。我也有一个控制器,这就是我需要它:
如果我在我的List的元素上clic,我必须切换我的视图并显示另一个。没什么难的吗? :)
好吧,现在......我的代码。首先,这是我的观点:
Ext.define('testProject.view.myView', {
extend: 'Ext.navigation.View',
xtype: 'myview',
config: {
scrollable: 'vertical',
iconCls: 'favorites',
title: 'My view',
items: [{
title: 'my view',
xtype: 'list',
loadingText: 'Loading..',
emptyText: '<div class="notes-list-empty-text">Nothing yet :)</div>',
itemTpl: '{title}',
itemId: 'favoritesList',
data: [
{ title: 'Elem 1' },
{ title: 'Elem 2' },
{ title: 'Elem 3' },
]
}],
listeners: [{
delegate: "#favoritesList",
event: "itemtap",
fn: "onFavoritesListDisclose"
}]
},
onFavoritesListDisclose:function(list, record, target, index, evt, options)
{
console.log("Debug #1");
this.fireEvent("onFavoritesListDisclose");
// Ext.Viewport.animateActiveItem({xtype:'showshopinformations'}, { type: 'slide', direction: 'left' }); <-- It's so… Not cool at all ! But it works !
}
});
这是我的控制者:
Ext.define("testProject.controller.myView", {
extend: "Ext.app.Controller",
config: {
refs: {
showShopInformations: 'showshopinformations', // <-- This is a ref on my the second view
favoritesList: '#favoritesList' // <-- This is a ref on my list
},
control: { // I think my problem is here...
favoritesList: { // <-- So I need to control my list and if I detect something...
onFavoritesListDisclose: 'onFavoritesListDisclose' // --> …Sencha'll call my onFavoritesListDisclose function. Right ?
}
}
},
onFavoritesListDisclose: function () {
console.log("onFavoritesListDisclose tap ! (since controller)"); // <-- This one is never call.
this.activateShopInformationView(); // <-- Change my view
},
activateShopInformationView: function() {
var shopInformationsView = this.getShowShopInformations();
Ext.Viewport.animateActiveItem(shopInformationsView, this.slideRightTransition);
},
slideRightTransition: {
type: 'slide',
direction: 'right'
},
launch: function () {
this.callParent();
},
init: function () {
this.callParent();
},
});
Soooo如果您有任何想法,那对我来说真的很高兴:)
度过愉快的一天。