【发布时间】:2014-08-09 03:19:28
【问题描述】:
我正在尝试创建一个控制器来为 android 制作一个开关按钮,因为 Titanium 中的那个没有我需要的 android 的全息外观,这个控制器工作正常,但在另一个控制器中有一个 addEventListener使用我的 Switch 控制器给我一个Object #<Controller> has no method addEventListener 错误。有人告诉我,我必须在我的开关控制器中定义 addEventListener 方法,但我不知道如何做到这一点。有什么想法吗?
客户.xml:
...
<View>
<Switch id="mySwitch" platform="ios"/>
<Require id="mySwitch" platform="android" src="customSwitch" />
</View>
...
customer.js:
...
$.mySwitch.addEventListener('change', function(e) {
// magic goes in here
});
...
customSwitch.js:
$.value = false;
$.setValue = function(value){
$.value = value;
}
var switchButton = Ti.UI.createButton({
width : 97,
height : 24,
backgroundImage : '/images/ic_switch_on.png',
visible : true
});
switchButton.applyProperties($.container.switchButton);
$.container.add(switchButton);
$.container.addEventListener('click', function(evt){
$.onClick && $.onClick({});
var currentValue = $.value;
if (currentValue) {
switchButton.backgroundImage = '/images/ic_switch_off.png';
$.setValue(!currentValue);
} else {
switchButton.backgroundImage = '/images/ic_switch_on.png';
$.setValue(currentValue);
}
});
【问题讨论】:
-
如果我在下面的回答没有帮助,您需要提供更多关于您正在尝试做什么的信息。在您的代码中,没有任何信息表明
$.container背后的内容以及您的错误消息和回溯究竟是什么样的。
标签: javascript android titanium titanium-mobile titanium-alloy