我已經實現這個解決方案: http://crm2011lookuppreview.codeplex.com/Dynamics CRM 2011網絡資源未在Chrome中顯示?
它在Outlook和IE瀏覽器的偉大工程,但預覽不顯示在Chrome在所有。我嘗試將jQuery .show()命令更改爲.style.display =「block」,但沒有任何結果。下面是解決方案中包含的JavaScript,負責構建HTML並顯示它。看起來Chrome根本沒有加載Web資源,因爲至少在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呈現,但我沒有得到很好的交叉兼容性精通簡單的東西。
我扔了一個警告(divTag.innerHTML);之前的jQuery .show();並在Outlook和IE瀏覽器顯示警報,但在Chrome中沒有讓我懷疑Web資源沒有加載或至少jscript不能觸發 – JustinCredible 2013-04-04 17:29:03
是否有可能給這個jsfiddle?另外,我很好奇爲什麼你使用了一些jQuery調用,但是隨後包含像這樣的語句'divTag = document.getElementById(webResourceId).contentWindow.document.getElementById('lookupDIV');'不是更好嗎?這通過一個簡單的jQuery調用?這可能與您的瀏覽器不兼容有關。 – Nate 2013-04-04 17:45:30
我沒有寫下來自我下載的解決方案的代碼。我只是想讓它適用於Chrome:P 至於jsfiddle,我不知道如何爲Dynamics CRM做...除了將上述代碼複製並粘貼到jsfiddle。 它看起來像jQuery的唯一用途是 $(divTag).slideDown(500); 我更改爲.show(),因爲我真的不想要幻燈片效果。我可以很容易地不使用jQuery,通過把它們拿出來,我嘗試了同樣的事情。這就像JavaScript只是不運行或 – JustinCredible 2013-04-04 17:48:23