1

我正在尝试从弹出窗口调用父页面上的函数。我不断收到错误Object doesn't support property or method '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();
                    });
4

1 回答 1

1

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

  1. 在顶层声明:

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

    $(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;
    });
    
于 2013-01-20T18:01:24.433 回答