简体   繁体   English

使用handsontable获取单元格的值-错误:方法不是函数

[英]Get the value of a cell with handsontable - Error : method is not a function

I want to get the value of one cell of my handsontable grid in my ajax callback function. 我想在我的ajax回调函数中获得handsontable网格的一个单元格的值。 So I can get my grid because when I do a alert(hot); 这样我就可以得到网格,因为当我执行alert(hot); it just tells me [Object][Object] and no 'undefined'. 它只是告诉我[Object][Object]而没有'undefined'。 But now, I'm trying to get one value and select one cell like this : 但是现在,我试图获得一个值并选择一个像这样的单元格:

alert(hotTraitement.getDataAtCell(1,1));

And Firebug tells me : 萤火虫告诉我:

hotTraitement.getDataAtCell is not a function hotTraitement.getDataAtCell不是函数

What am I doing wrong ? 我究竟做错了什么 ?

EDIT : 编辑:

I declare my handsontable in a window.load like this : 我像这样在window.load中声明了handsontable:

$(window).load(function(){
            var data = [];


            var container = document.getElementById('tab_traitement');
            var hotTraitement = new Handsontable(container, {
                data: data_traitement,
                stretchH: 'all',
                minSpareRows: 1,
                observeChanges : true,
                rowHeaders: false,
                colHeaders: false,
                contextMenu: true,
                ...

            });
});

And I pass my hotTraitement in parameter like this : 我通过hotTraitement的参数传递hotTraitement

 function insertTraitementCallback(responseObject,ioArgs,hotTraitement)

And it seems working because I get [object Object] and no "undefined". 它似乎有效,因为我得到了[object Object]并且没有“ undefined”。

If I'm wrong then what should I do to have hotTraitement available in my callback ? 如果我错了,那该怎么办才能在回调中提供hotTraitement?

EDIT 2 : 编辑2:

In my function, I just try to display the content of one cell for now, to see if I can get my hotTraitement : 在我的函数中,我现在仅尝试显示一个单元格的内容,以查看是否可以获取hotTraitement

function insertTraitementCallback(responseObject,ioArgs,hotTraitement)
{
    alert(hotTraitement.getDataAtCell(1,1));
}

And Firebug tells me that "hotTraitement.getDataAtCell is not a function". 而且Firebug告诉我“ hotTraitement.getDataAtCell不是函数”。

EDIT 3 : 编辑3:

function insertTraitementCallback(responseObject,ioArgs)
            {
                var idTableau ='tab_traitement';
                var table = 'traitement';
                var indexCell = 1;
                var jsonobject = eval(responseObject);
                console.log(hotTraitement.getDataAtCell(1,1));
                callback(jsonobject,data_traitement,idTableau,table, indexCell,'insert');               
            }
          var data = [];
</script>

<script type="text/javascript">
    $(document).ready(function()
    {
        $(window).load(function(){
            container = document.getElementById('tab_traitement');
            hotTraitement = new Handsontable(container, {
                data: data_traitement,
                stretchH: 'all',
                minSpareRows: 1,
                observeChanges : true,
                rowHeaders: false,
                colHeaders: false,
                contextMenu: true,
                ...
            });

        var table = 'traitement';


        $('#submit_button_traitement').click(function()
        {

            var id_essai = $('.session').text();
            arrayDataIDTraitement.length = 0;
            arrayDataCodeTraitement.length = 0;
            var idTable='id_traitement';

            $.post("ajaxUpdate.php",{arr:data_traitement,id_essai,table,idTable},insertTraitementCallback,'json');

            for(var i =1; i<data_traitement.length-1 ; i++) //Création du tableau pour les listes déroulantes
            {                   
                arrayDataIDTraitement.push(data_traitement[i][1]);
                arrayDataCodeTraitement.push(data_traitement[i][0]);
            }
        });
    });

You have a scoping issue. 您有范围问题。 hotTraitement will not be available in the callback. hotTraitement在回调中将不可用。 You need to pass hotTraitement to the ajax settings options and then use that variable in the callback. 您需要将hotTraitement传递给ajax设置选项,然后在回调中使用该变量。 The context in which the callback is executed is different. 执行回调的上下文不同。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM