Javascript 如何在函数中调用变量?
我有一些varD变量格式的数据,如下所示:Javascript 如何在函数中调用变量?,javascript,jquery,function,Javascript,Jquery,Function,我有一些varD变量格式的数据,如下所示: [{period: '2013', iphone: 0, ipad: 4, itouch:0}, {period: '2013', iphone: 3, ipad: 0, itouch:90}, {period: '2013', iphone: 1, ipad: 0, itouch:13}] 我想调用jquery图表函数 drawHeroArea : function (varD) {
[{period: '2013', iphone: 0, ipad: 4, itouch:0},
{period: '2013', iphone: 3, ipad: 0, itouch:90},
{period: '2013', iphone: 1, ipad: 0, itouch:13}]
我想调用jquery图表函数
drawHeroArea : function (varD) {
!verboseBuild || console.log('proton.dashboard.drawHeroArea()');
if($('#hero-area').length)
proton.dashboard.graph.Area = Morris.Area({
element: 'hero-area',
data: varD,
xkey: 'period',
ykeys: ['iphone', 'ipad', 'itouch'],
labels: ['iPhone', 'iPad', 'iPod Touch'],
pointSize: 2,
hideHover: 'auto'
});
}
数据在警报功能中正确显示。但是当我添加数据:varD,
时,它就不起作用了。请任何人告诉我问题在哪里,或者如何调用数据:
这种方法工作正常
drawHeroArea : function (varD) {
!verboseBuild || console.log('proton.dashboard.drawHeroArea()');
if($('#hero-area').length)
proton.dashboard.graph.Area = Morris.Area({
element: 'hero-area',
data:
[
{period: '2013', iphone: 0, ipad: 4, itouch:0},
{period: '2013', iphone: 3, ipad: 0, itouch:90},
{period: '2013', iphone: 1, ipad: 0, itouch:13},
{period: '2013', iphone: 0, ipad: 0, itouch:7},
{period: '2013', iphone: 0, ipad: 0, itouch:13},
{period: '2013', iphone: 0, ipad: 0, itouch:9},
{period: '2013', iphone: 0, ipad: 0, itouch:9},
{period: '2013', iphone: 0, ipad: 1, itouch:20},
{period: '2013', iphone: 0, ipad: 0, itouch:11},
{period: '2013', iphone: 0, ipad: 1, itouch:20},
{period: '2014', iphone: 0, ipad: 0, itouch:19},
{period: '2014', iphone: 0, ipad: 1, itouch:24},
{period: '2014', iphone: 0, ipad: 0, itouch:26},
{period: '2014', iphone: 0, ipad: 1, itouch:14},
{period: '2014', iphone: 0, ipad: 0, itouch:2},
{period: '2014', iphone: 0, ipad: 0, itouch:3},
{period: '2014', iphone: 0, ipad: 1, itouch:3},
{period: '2014', iphone: 0, ipad: 0, itouch:2},
{period: '2015', iphone: 0, ipad: 1, itouch:16},
{period: '2015', iphone: 0, ipad: 0, itouch:3},
{period: '2015', iphone: 0, ipad: 0, itouch:25},
{period: '2015', iphone: 0, ipad: 0, itouch:14},
{period: '2015', iphone: 0, ipad: 0, itouch:1}
],
xkey: 'period',
ykeys: ['iphone', 'ipad', 'itouch'],
labels: ['iPhone', 'iPad', 'iPod Touch'],
pointSize: 2,
hideHover: 'auto'
});
}
这应该起作用:
proton.dashboard.graph.Area.data=varD;
已定义的对象应能正常工作@Mohit drawHeroArea(varD)@Uchiha你是什么意思…?@AyazShah
sql
和mysql
与这个姿势有什么关系?没有关系……这里很好