Javascript 从json对象动态调用jquery函数

Javascript 从json对象动态调用jquery函数,javascript,jquery,json,node.js,Javascript,Jquery,Json,Node.js,比如说,我有来自API的JSON数据。我想使用JSON键的值来调用用户定义的jquery函数 我从服务器获取的数据是: { "question":"What is your age?", "graphType":"horizontalBar", } 现在我的脚本中有一个函数名为horizontalBar ( function( $ ){ $.fn.horizontalBar = function(data){ //do some stuff } })( jQuery );

比如说,我有来自API的JSON数据。我想使用JSON键的值来调用用户定义的jquery函数

我从服务器获取的数据是:

{
    "question":"What is your age?",
    "graphType":"horizontalBar",
}
现在我的脚本中有一个函数名为horizontalBar

( function( $ ){
$.fn.horizontalBar = function(data){
   //do some stuff
}
})( jQuery ); 
现在我想要这样的东西来调用函数:

$().json.graphType(data);
以下是我搜索并试图称之为的内容:

window[json.graphType](data); 
那么:

$(<selector of target object>)[json.graphType](data); 

好吧,如果这是适合您的解决方案,那么您可能应该单击它作为“接受答案”?;-)
$()[json.graphType](data);