Jqgrid 从子窗口调用父窗口函数

Jqgrid 从子窗口调用父窗口函数,jqgrid,dynamics-crm-2011,Jqgrid,Dynamics Crm 2011,我试图从弹出窗口调用父页面上的函数。我不断得到错误对象不支持属性或方法“GetValueFromChild”。我相信错误在弹出窗口的这一行- window.top.opener.parent.Xrm.Page.GetValueFromChild(person)。我尝试使用window.opener.GetValueFromChild(person)但仍然会得到相同的错误。非常感谢您的帮助。这是密码- //parent $(document).ready(function () {

我试图从弹出窗口调用父页面上的函数。我不断得到错误
对象不支持属性或方法“GetValueFromChild”。
我相信错误在弹出窗口的这一行-
window.top.opener.parent.Xrm.Page.GetValueFromChild(person)。我尝试使用
window.opener.GetValueFromChild(person)但仍然会得到相同的错误。非常感谢您的帮助。这是密码-

    //parent
    $(document).ready(function () {
        // This needs to be called from Child window
        function GetValueFromChild(person) {
            alert(person.Id);
            alert(person.Name);
            alert(person.Market);
        }    
    });


//parent - jqgrid

    colModel: [
                            {
                                name: 'Person', index: 'PersonName', width: 70, editable: true, edittype: 'button',
                                editoptions: {
                                    value: 'Select',
                                    dataEvents: [{
                                        type: 'click',
                                        fn: function (elem) {
                                            var left = (screen.width / 2) - (700 / 2);
                                            var top = (screen.height / 2) - (550 / 2);

                                            var popup = window.open("popup.htm", "popup", "resizable=1,copyhistory=0,menubar=0,width=700,height=550,left='+left+',top='+top");
                                            popup.focus();
                                        }
                                    }]
                                }
                            },
//弹出窗口。此页面有另一个jqgrid和一个OK按钮

  $('#btnOK').click(function() {
                        var person= {
                            Id: grid.jqGrid('getCell', grid.getGridParam('selrow'), 'Id'),
                            Name: grid.jqGrid('getCell', grid.getGridParam('selrow'), 'Name'),
                            Market: grid.jqGrid('getCell', grid.getGridParam('selrow'), 'Market')
                        };

                        window.top.opener.parent.Xrm.Page.GetValueFromChild(person); //Error is on this line.
                        window.close();
                    });

您的
GetValueFromChild
的范围是您的
ready
回调。如果它不需要访问其他作用域函数和变量,那么只需在顶层声明它即可。如果它确实需要访问它们,您需要在回调中创建对它的全局引用

  • 在最高层宣布:

    // This needs to be called from Child window
    function GetValueFromChild(person) {
        alert(person.Id);
        alert(person.Name);
        alert(person.Market);
    }
    
  • 从范围导出:

    $(document).ready(function () {
        // This needs to be called from Child window
        function GetValueFromChild(person) {
            alert(person.Id);
            alert(person.Name);
            alert(person.Market);
        }
        window.GetValueFromChild = GetValueFromChild;
    });
    

  • 您的
    GetValueFromChild
    的范围是您的
    ready
    回调。如果它不需要访问其他作用域函数和变量,那么只需在顶层声明它即可。如果它确实需要访问它们,您需要在回调中创建对它的全局引用

  • 在最高层宣布:

    // This needs to be called from Child window
    function GetValueFromChild(person) {
        alert(person.Id);
        alert(person.Name);
        alert(person.Market);
    }
    
  • 从范围导出:

    $(document).ready(function () {
        // This needs to be called from Child window
        function GetValueFromChild(person) {
            alert(person.Id);
            alert(person.Name);
            alert(person.Market);
        }
        window.GetValueFromChild = GetValueFromChild;
    });