(类型:负载)是什么意思?

发布于 2024-12-11 19:42:16 字数 3671 浏览 1 评论 0原文

有谁知道Javascript ( type: load ) 是什么意思?我收集它是一个事件,但它应该是一个对象?

任何建议表示赞赏!

中断-> var data = new google.visualization.DataTable(jsonData.jsonObj);

使用 Google 图表....

charts.js

(function($){
    
    
    var charts = {
        
        init: function(){
            
            this.services();
        },
        services: function(){
            var data = {
                uri : SITEURL + '/moduleTest/servicelist', //siteurl defined in index.php
                div : 'service-chart',
                title : 'Service List'
            }
            charts.ajaxCallback(data);
        },
        ajaxCallback : function(data){
            $.ajax({
               url : data.uri,
               type : 'POST',
               dataType : 'json',
               success : function(callback){

                   var jsonData = {
                       div : data.div,
                       jsonObj : callback,
                       title : data.title
                   }
                   drawCharts(jsonData);
                   
               }
            });
        }
        
    }
    
    $(function(){
       charts.init(); 
    });
    
})(jQuery);

google.load('visualization', '1.0', {'packages':['corechart']});

google.setOnLoadCallback(drawCharts);

function drawCharts(jsonData){
   
    var data = new google.visualization.DataTable(jsonData.jsonObj);//Break point ( type : load )
    
    var options = 
        {
             'title': jsonData.title,
             'width':250,
             'height':300
         };

  var chart = new google.visualization.PieChart(document.getElementById(jsonData.div));
  chart.draw(data, options);

}

Services.php(功能测试)

 public function servicelist(){ //TEST data
        if($this->input->is_ajax_request()){
            echo "
                {
                     cols: [{id: 'task', label: 'Employee Name', type: 'string'},
                            {id: 'startDate', label: 'Start Date', type: 'date'}],
                     rows: [{c:[{v: 'Mike'}, {v: new Date(2008, 1, 28), f:'February 28, 2008'}]},
                            {c:[{v: 'Bob'}, {v: new Date(2007, 5, 1)}]},
                            {c:[{v: 'Alice'}, {v: new Date(2006, 7, 16)}]},
                            {c:[{v: 'Frank'}, {v: new Date(2007, 11, 28)}]},
                            {c:[{v: 'Floyd'}, {v: new Date(2005, 3, 13)}]},
                            {c:[{v: 'Fritz'}, {v: new Date(2011, 6, 1)}]}
                           ]
                   }

                ";
        }
    }

好的,我可以这个问题没有任何意义(当时是早上 6 点)。

我将一个 json 对象传递给我的谷歌图表构造函数(drawCharts())。

var jsonData =  {
                         cols: [{id: 'task', label: 'Employee Name', type: 'string'},
                                {id: 'startDate', label: 'Start Date', type: 'date'}],
                         rows: [{c:[{v: 'Mike'}, {v: new Date(2008, 1, 28), f:'February 28, 2008'}]},
                                {c:[{v: 'Bob'}, {v: new Date(2007, 5, 1)}]},
                                {c:[{v: 'Alice'}, {v: new Date(2006, 7, 16)}]},
                                {c:[{v: 'Frank'}, {v: new Date(2007, 11, 28)}]},
                                {c:[{v: 'Floyd'}, {v: new Date(2005, 3, 13)}]},
                                {c:[{v: 'Fritz'}, {v: new Date(2011, 6, 1)}]}
                               ]
                       }

    console.log(typeof jsonData) === object // Correct, what I expect!
    console.log(jsonData) === load // not what I expect, I expect json object

Does anyone know what Javascript ( type: load ) means? I gather its an event however it should be an object?

Any advice appreciated!

BREAK -> var data = new google.visualization.DataTable(jsonData.jsonObj);

Working with Google charts....

charts.js

(function($){
    
    
    var charts = {
        
        init: function(){
            
            this.services();
        },
        services: function(){
            var data = {
                uri : SITEURL + '/moduleTest/servicelist', //siteurl defined in index.php
                div : 'service-chart',
                title : 'Service List'
            }
            charts.ajaxCallback(data);
        },
        ajaxCallback : function(data){
            $.ajax({
               url : data.uri,
               type : 'POST',
               dataType : 'json',
               success : function(callback){

                   var jsonData = {
                       div : data.div,
                       jsonObj : callback,
                       title : data.title
                   }
                   drawCharts(jsonData);
                   
               }
            });
        }
        
    }
    
    $(function(){
       charts.init(); 
    });
    
})(jQuery);

google.load('visualization', '1.0', {'packages':['corechart']});

google.setOnLoadCallback(drawCharts);

function drawCharts(jsonData){
   
    var data = new google.visualization.DataTable(jsonData.jsonObj);//Break point ( type : load )
    
    var options = 
        {
             'title': jsonData.title,
             'width':250,
             'height':300
         };

  var chart = new google.visualization.PieChart(document.getElementById(jsonData.div));
  chart.draw(data, options);

}

Services.php ( function test )

 public function servicelist(){ //TEST data
        if($this->input->is_ajax_request()){
            echo "
                {
                     cols: [{id: 'task', label: 'Employee Name', type: 'string'},
                            {id: 'startDate', label: 'Start Date', type: 'date'}],
                     rows: [{c:[{v: 'Mike'}, {v: new Date(2008, 1, 28), f:'February 28, 2008'}]},
                            {c:[{v: 'Bob'}, {v: new Date(2007, 5, 1)}]},
                            {c:[{v: 'Alice'}, {v: new Date(2006, 7, 16)}]},
                            {c:[{v: 'Frank'}, {v: new Date(2007, 11, 28)}]},
                            {c:[{v: 'Floyd'}, {v: new Date(2005, 3, 13)}]},
                            {c:[{v: 'Fritz'}, {v: new Date(2011, 6, 1)}]}
                           ]
                   }

                ";
        }
    }

Ok I may not have made any sense with the question(it was 6am).

I am passing in a json object to the my google charts constructor ( drawCharts() ).

var jsonData =  {
                         cols: [{id: 'task', label: 'Employee Name', type: 'string'},
                                {id: 'startDate', label: 'Start Date', type: 'date'}],
                         rows: [{c:[{v: 'Mike'}, {v: new Date(2008, 1, 28), f:'February 28, 2008'}]},
                                {c:[{v: 'Bob'}, {v: new Date(2007, 5, 1)}]},
                                {c:[{v: 'Alice'}, {v: new Date(2006, 7, 16)}]},
                                {c:[{v: 'Frank'}, {v: new Date(2007, 11, 28)}]},
                                {c:[{v: 'Floyd'}, {v: new Date(2005, 3, 13)}]},
                                {c:[{v: 'Fritz'}, {v: new Date(2011, 6, 1)}]}
                               ]
                       }

    console.log(typeof jsonData) === object // Correct, what I expect!
    console.log(jsonData) === load // not what I expect, I expect json object

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

偏爱自由 2024-12-18 19:42:16

在我看来,就像代码中的这个注释:

//Break point ( type : load )

对于某些代理(可能是寻找某些注释的调试器)来说,意味着在页面加载时应该在此处设置一个断点。

It looks to me like this comment in the code:

//Break point ( type : load )

means to some agent (probably a debugger looking for certain comments) that there should be a breakpoint set here at page load time.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文