简体   繁体   English

Titanium如何从函数名称数组中调用函数?

[英]Titanium How do i call functions from an array of function names?

Hello I'm working with Titanium Alloy and I have a problem with call some function from other files: I have this file in /lib: validation.js 您好,我正在使用钛合金,并且在从其他文件调用某些函数时遇到问题:我在/ lib中有此文件:validation.js

exports.isInt=function(obj){
if(parseInt(obj.value) != parseFloat(obj.value)) {
    return false;
}
else{
    return true;
}

}; };

and in my controller i call it: controller1.js 在我的控制器中,我称之为:controller1.js

var split = data.pregunta.attributes.pr_validacion.split(','); //{'function1','function2'}
var valida = require('validation');
for (var p in split) {
    alert(split[p]); //show: 'function1'
    if(! valida.split[p]()){
        return false;
    }
}

But it shows me a message that split[0] is not a valid object, how I cando to make me take the name of the function? 但是它向我显示了一条消息,说明split [0]不是有效的对象,如何使我取这个函数的名称?

Thanks U! 谢谢你!

You should use valida[split[p]] in your controller1.js: 您应该在controller1.js中使用valida [split [p]]:

var split = data.pregunta.attributes.pr_validacion.split(','); //{'function1','function2'}
var valida = require('validation');
for (var p in split) {
    alert(split[p]); //show: 'function1'
    if(! valida[split[p]]()){
        return false;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Javascript 如何从函数名称数组调用函数 - Javascript How do i call functions from an array of function names Titanium:如何从此函数获取数据? - Titanium: How do I get the data from this function? 调用函数时如何传递参数名称? - How do I pass in argument names when I call a function? 单击锚标记后,如何从功能页面调用特定功能 - How do i call a specific function from a functions page when an anchor tag is clicked 如何在Javascript中正确调用匿名函数? - How do I correctly call a functions of anonymous function in Javascript? 如何通过使用onclick事件中的函数并使用循环从函数中的数组中计数函数来调用多个JavaScript函数? - How to call multiple JavaScript functions by using function in onclick event and using loop to count functions from array in function? 在Javascript中,如果有一个对象具有很多作为函数的属性,那么如何将它们转换为(函数名称的)字符串数组? - In Javascript, if there is an object with a lot of properties that are functions, how do you convert them to array of strings (of the function names)? 在Webview中调用JS的Titanium函数 - Call Titanium function from JS in Webview Appcelerator / Titanium-从函数内部调用变量 - Appcelerator/Titanium - Call variable from within function 打印功能数组的功能名称 - Print function names of an array of functions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM