0

我已经实现了这个解决方案: http ://crm2011lookuppreview.codeplex.com/

它在 Outlook 和 IE 上运行良好,但在 Chrome 上根本不显示预览。我尝试将 jQuery .show() 命令更改为 .style.display = "block" 但没有。下面是解决方案中包含的负责构建 HTML 并显示它的 JavaScript。Chrome 似乎根本没有加载网络资源,因为至少在 IE 上,资源的轮廓是可见的,然后数据会出现并填充该轮廓。在 Chrome 中,只有空白区域。但这可能是 Chrome 的渲染方式,我不知道......

//LookupPreviewScript.js
///<reference path="XrmPage-vsdoc.js"/>
var XrmPage;
var popWindow;
var _VerticalLayout = "V";
var _HorizontalLayout = "H";
var _ZLayout = "Z";
var _NLayout = "N";

function LoadLookPreviewDelayed(webResourceId, lookupAttributeId, columnList, layout)
{
    myFn = function(){LoadLookPreview(webResourceId, lookupAttributeId, columnList, layout);}
    setTimeout(myFn, 2000);
    Xrm.Page.getAttribute(lookupAttributeId.toLowerCase()).addOnChange(myFn);
}

function FormHTMLTable(divTag, controlSet, layout)
{
    var str = "";
    if(layout == _VerticalLayout)
    {
        str = "<table><tbody>";
        for(var k=0; k < controlSet.length; k++){
        str += "<tr>";
        str += "<td class='headerCss'>" + controlSet[k].attributeDisplayName + "</td>";
        str += "<td>" + controlSet[k].attributeValue + "</td>";
        str += "</tr>";
        }
        str += "</tbody></table>";                              
    }
    else if(layout == _ZLayout)
    {
        str = '<table>';
        str += '<tbody>';
        for (var j = 0; j < controlSet.length; j++) {
            var index = j + 1;
            str += "<tr>"
            str += "<td class='headerCss'>" + controlSet[j].attributeDisplayName + "</td>";
            str += "<td>" + controlSet[j].attributeValue + "</td>";
            str += "<td class='seperator'></td>";
            if(index < controlSet.length)
            {
                str += "<td class='headerCss'>" + controlSet[index].attributeDisplayName + "</td>";
                str += "<td>" + controlSet[index].attributeValue + "</td>";
            }
            str += "</tr>"
            j++;
        }
        str += '</tbody>'
        str += '</table>';
    }
    else if(layout == _NLayout)
    {
        str = '<table>';
        str += '<tbody>';
        var half = Math.round(controlSet.length / 2)
        for (var j = 0; j < controlSet.length; j++) {
            var index = j + half;
            if (j < half) {
                str += "<tr>"
                str += "<td class='headerCss'>" + controlSet[j].attributeDisplayName + "</td>";
                str += "<td>" + controlSet[j].attributeValue + "</td>";
                str += "<td class='seperator'></td>";
                if (index < controlSet.length) {
                    str += "<td class='headerCss'>" + controlSet[index].attributeDisplayName + "</td>";
                    str += "<td>" + controlSet[index].attributeValue + "</td>";
                }
                str += "</tr>"
            }
        }
        str += '</tbody>'
        str += '</table>';
    }
    else 
    {
        str = "<table><thead><tr>";
        for(var k=0; k < controlSet.length; k++){
        str += "<th>" + controlSet[k].attributeDisplayName + "</th>";
        }
        str += "</tr></thead><tbody><tr>";
        for (var i = 0; i < controlSet.length; i++){
        str += "<td>" + controlSet[i].attributeValue + "</td>";
        }
        str += "</tr></tbody></table>";
     }
     divTag.innerHTML = str;
     $(divTag).slideDown(1000);
}

function LoadLookPreview(webResourceId, lookupAttributeId, columnList, layout)
{
   var divTag;
   var webResource = Xrm.Page.getControl(webResourceId);
   var columnSet = new Array();
   var columnHeaders = new Array();
   var controlSet = new Array();

   successCallBack =  function (attributeCollection) {
                 for(var k=0; k < controlSet.length; k++)
                 {
                    for (var i = 0; i < attributeCollection.length; i++) 
                    {
                        if(attributeCollection[i].attributeName == controlSet[k].attributeLogicalName)
                        {
                             controlSet[k].attributeValue = attributeCollection[i].attributeValue;
                             break;
                        }
                    }
                 }

                 FormHTMLTable(divTag, controlSet, layout);
          };

        errorCallBack =  function (error) {
             divTag.innerHTML = "<span class='error'>" + error.message + "</span>";
             $(divTag).slideDown(500);
         };

   if(webResource == null)
   {
       alert('No WebResource found with Id = ' + webResourceId);
   }
   else
   {
        divTag = document.getElementById(webResourceId).contentWindow.document.getElementById('lookupDIV');
        if(divTag != null)
        {
            divTag.display = "none";
            var columns = columnList.split('|');
            for(var i = 0 ; i < columns.length; i++)
            {
                var s = columns[i].split('#');
                var _control = new Object();
                _control.attributeDisplayName = s[0];
                _control.attributeLogicalName = s[1].toLowerCase().replace(/^\s+|\s+$/g, '')
                _control.attributeValue = '';
                controlSet.push(_control);

                columnSet.push(s[1].toLowerCase().replace(/^\s+|\s+$/g, ''));
            }

            if(Xrm.Page.getAttribute(lookupAttributeId.toLowerCase()) != null && Xrm.Page.getAttribute(lookupAttributeId.toLowerCase()).getValue() != null)
            {
                var id = Xrm.Page.getAttribute(lookupAttributeId).getValue()[0].id;
                var entityName = Xrm.Page.getAttribute(lookupAttributeId).getValue()[0].entityType;
                SDK.RetrieveData.RetrieveRequestAsync(entityName, id, columnSet, successCallBack, errorCallBack);
            }
            else
            {
                FormHTMLTable(divTag, controlSet, layout);
            }
        }
        else
        {
            alert("Error in Loading Web Resource (DIV is NULL)")
        }
   }
}

我猜这对于 DIV 的渲染方式或时间很简单,但我并不精通交叉兼容性。

4

1 回答 1

0

该问题似乎与 Chrome 和 Dynamics CRM 2011 SDK 函数 SDK.RetrieveData 存在某种不兼容。我刚刚打开了解决方案中包含的 SDK.RetrieveData.js 文件,并用此 URL 指定的代码替换了它,她现在的工作就像一个魅力!

http://crm2011lookuppreview.codeplex.com/discussions/431830

于 2013-04-04T20:23:12.793 回答