问题
I am a new to Sencha Touch, though I have little knowledge about MVC, I am getting an error while I try to build an application following the video tutorial of Sencha Touch 2 as:
Uncaught TypeError: Cannot call method 'substring' of undefined sencha-touch-all.js:35
The code is as follows:
app.js:
Ext.Loader.setConfig({
enabled: true
});
Ext.application({
name: 'SBR',
controllers: [
'Main'
],
launch: function(){
Ext.create('Ext.TabPanel',{
fullscreen: true,
tabBarPosition: 'bottom',
items: [
{
xtype: 'homepanel'
},
{
xtype: 'carousel',
title: 'Blog',
iconCls: 'star',
html: 'Student Blog',
items: [
{
xtype: 'image',
src: 'resources/images/icon1.png'
},
{
xtype: 'image',
src: 'resources/images/icon2.png'
}]
},
{
title: 'Enter your Comments',
iconCls: 'star',
html: 'Enter your Comments'
}
]
});
}
});
Home.js - the View
Ext.define('SBR.view.Home', {
extend: 'Ext.Panel',
xtype: 'homepanel',
config:{
title: 'Home',
iconCls: 'home',
html: 'Html through View'
}
});
Main.js - The Controller
Ext.define('SBR.controller.Main',{
extend: 'Ext.app.Controller',
views: ['Home'],
init: function(){
console.log('It is tested - Ok');
}
});
If the code of the view (Home.js) is set in the app.js without using a xtype, it works fine, but when I define a view and try to access the view by xtype from app.js it does not work and throws the above exception, although it logs the message passed in the controller successfully in the console.
Browser Used : Chrome
IDE : Aptana
Sencha Touch Version: 2.0
回答1:
You need to add all the View, Store and Model classes in app.js just the same way you added the controller:
controllers: [
'Main'
],
views : [
'Home'
]
This should make it work.
来源:https://stackoverflow.com/questions/16439771/uncaught-typeerror-cannot-call-method-substring-of-undefined-sencha-touch-all-js