问题描述
我想知道Sencha Touch类'Ext.app.Controller'的'refs'属性.我看了一个视频教程,其中构建了一个简单的contactForm.不,我没有尝试为我的应用程序构建联系表单,但出现错误:'Uncaught TypeError:对象[object Object]没有方法'getContactForm'
i am wondering about the 'refs' attribute of Sencha Touch class 'Ext.app.Controller'.I saw a video tutorial where a simple contactForm was built. No i've tried to build a contact form for my app and i get an error: 'Uncaught TypeError: Object [object Object] has no method 'getContactForm''
这是我的控制器
Ext.define('MyFirstApp.controller.Main', {
extend: 'Ext.app.Controller',
views: ['Viewport', 'Home'],
refs: [
{
ref: 'contactForm',
selector: '#contactForm'
}
],
init: function() {
this.control({
'button[action=submitContact]': {
tap: 'submitContactForm'
}
});
},
submitContactForm: function() {
var form = this.getContactForm();
form.submit({
url: 'contact.php'
});
}
});
我想'refs'有点问题,在视频中,那个家伙说将创建"getContactForm"方法是因为"contactForm"的"ref"属性,但事实并非如此.我在这里做错了吗?谢谢您!
I guess it's something wrong with the 'refs', in the video that guy said the "getContactForm" method will be created because of the "ref" attribute of "contactForm" but it doesn't. What am i doing wrong here?..Thanks for help!
推荐答案
看来您可能将refs配置错误.这是一个简单的控制器:
It looks as though you may have the refs configured wrong. Here's a simple controller:
Ext.define('App.controller.Main', {
extend: 'Ext.app.Controller',
config: {
refs: {
main: 'mainpanel'
}
}
});
mainpanel
是xtype
或可能是CSS选择器,而main
将为您提供getMain()
,就像视频中提到的一样.
mainpanel
is an xtype
or could be a css selector and main
will give you getMain()
like what was talked about in the video.
这篇关于Sencha Touch 2.0 Controller refs属性不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!