[英]Uncaught TypeError: Cannot read property 'x' of undefined Morris.js
I'm going nuts and I can't figure out what is causing this error. 我疯了,我不知道是什么导致了这个错误。
My Javascript: 我的Javascript:
<script>
$(document).ready(function() {
var jqxhr = $.getJSON("rest/scriptruns/VeloxMorgana", function() {
//VeloxMorgana.setData('[{"period":"2014-07-15","VeloxMorgana":1},{"period":"2014-07-16","VeloxMorgana":47}]');
});
jqxhr.complete(function() {
if ($('#VeloxMorgana').length) {
var week_data = jqxhr;
var VeloxMorgana = Morris.Line({
element : 'VeloxMorgana',
data : week_data,
xkey : 'period',
ykeys : ['VeloxMorgana'],
labels : ['VeloxMorgana'],
events : ['2014-07-10', '2014-07-17']
});
}
});
});
</script>
My HTML 我的HTML
<!-- Widget ID (each widget will need unique ID)-->
<div class="jarviswidget" id="wid-id-7" data-widget-editbutton="false">
<!-- widget options:
usage: <div class="jarviswidget" id="wid-id-0" data-widget-editbutton="false">
data-widget-colorbutton="false"
data-widget-editbutton="false"
data-widget-togglebutton="false"
data-widget-deletebutton="false"
data-widget-fullscreenbutton="false"
data-widget-custombutton="false"
data-widget-collapsed="true"
data-widget-sortable="false"
-->
<header>
<span class="widget-icon"> <i class="fa fa-bar-chart-o"></i> </span>
<h2>Time Graph</h2>
</header>
<!-- widget div-->
<div>
<!-- widget edit box -->
<div class="jarviswidget-editbox">
<!-- This area used as dropdown edit box -->
</div>
<!-- end widget edit box -->
<!-- widget content -->
<div class="widget-body no-padding">
<div id="VeloxMorgana" class="chart no-padding"></div>
</div>
<!-- end widget content -->
</div>
<!-- end widget div -->
</div>
<!-- end widget -->
It loaded when I statically set the data, but when I use JSON it just freaks. 当我静态设置数据时,它就会加载,但是当我使用JSON时,它就怪胎了。
Here is the JSON it loads in when I call it using the ajax json feature and the load data (i've tried just putting it straight into the data from finishing the json request, same result). 这是当我使用ajax json功能调用它并加载数据时加载的JSON(我已经尝试过将JSON请求完成后直接放入数据中,结果相同)。
[
{
"period":"2014-07-15",
"VeloxMorgana":1
},
{
"period":"2014-07-16",
"VeloxMorgana":47
}
]
The jqxhr
is just the promise object for your XHR request, it doesn't actually contain the data that was received. jqxhr
只是XHR请求的jqxhr
对象,它实际上不包含接收到的数据。
Since you don't really deal with failure at all, I could recommend just using the success callback straight away: 由于您根本不真正处理失败,因此我建议您立即使用成功回调:
$.getJSON("rest/scriptruns/VeloxMorgana", function(data) {
if ($('#VeloxMorgana').length) {
Morris.Line({
element : 'VeloxMorgana',
data : data,
xkey : 'period',
ykeys : ['VeloxMorgana'],
labels : ['VeloxMorgana'],
events : ['2014-07-10', '2014-07-17']
});
}
});
Also, the documentation states: 此外, 文档指出:
The
jqXHR.success()
,jqXHR.error()
, andjqXHR.complete()
callback methods introduced in jQuery 1.5 are deprecated as of jQuery 1.8.jQuery 1.5中不推荐使用
jqXHR.success()
,jqXHR.error()
和jqXHR.complete()
回调方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.