Javascript xPages 错误
Javascript in xPages error
我在 xPage 中有以下代码来使用 gridx。当它出于某种原因运行时,它会将我的第二个装饰器函数中的 > 符号转换为 &,这会导致 javascript interpereter 抛出错误。谁能看出哪里出了问题?
<script>
require(
[
"gridx/Grid",
"dojo/store/Memory",
"gridx/modules/ColumnResizer",
"gridx/modules/NestedSort",
"gridx/modules/Filter",
"gridx/modules/Bar",
"gridx/core/model/cache/Sync",
"dojo/domReady!"
],
function(Grid, MemoryStore, Resizer, NestedSort, Filter, Bar, Cache)
{
var columns = [
{id: 'ownerName', field: 'OccupantName', name: 'Name', width: '150px'},
{id: 'propertyAddress', field: 'PropertyAddress', name: 'Property Name'},
{id: 'contactInfo1', field: 'ContactInfo1', name: 'Contact Information 1',
decorator: function(value)
{
try
{
if( typeof( value ) === "undefined" )
return "";
if( typeof( value ) === "string" )
return value;
myLen = value.toString().length;
// THIS WORKS FINE
if( myLen > 35 )
return value.join( "<br></br>" );
return "";
} catch (e)
{
console.error('error decorating date: ' );
}
}
},
{id: 'contactInfo2', field: 'ContactInfo2', name: 'Contact Information 2',
decorator: function(value)
{
try
{
if( typeof( value ) === "undefined" )
return "";
if( typeof( value ) === "string" )
return value;
myLen = value.toString().length;
// THIS GETS TRANSLATED TO >
if( myLen > 35 )
return value.join( "<br></br>" );
return "";
} catch (e)
{
console.error('error decorating date: ' );
}
}
},
{id: 'myTier', field: 'MyTier', name: 'Tier'},
{id: 'my', field: 'MyFloor', name: 'Floor'}
];
// Make an AJAX call to look up the full data set and store it locally for fast access
dojo.xhr.get({
url:"xpRestSTAROccupantInfo.xsp/gridDataSTAROccupantInfo",
handleAs:"json",
load: function(restData){
// Load the data into a local memory store
var store = new MemoryStore({
data: restData,
idProperty: '@noteid'
});
grid = new Grid({
id: "my_gridX",
cacheClass: Cache,
store: store,
autoHeight: true,
structure: columns,
barTop: [
"gridx/support/Summary",
"gridx/support/DropDownPager",
{pluginClass: "gridx/support/QuickFilter", style: 'text-align: right;'}
],
barBottom: [
"gridx/support/LinkSizer",
{pluginClass: "gridx/support/LinkPager", style: 'text-align: right;'}
],
sortInitialOrder: {colId: 'ownerName', descending: false},
modules: [
Resizer,
NestedSort,
Filter,
Bar
]
});
//Put it into the DOM tree.
grid.placeAt('gridX_Here');
grid.startup();
},
error: function(msg, args) {
console.error('Error loading grid data: ' + msg );
alert('There was an error loading the data: ' + msg);
}
});
});
</script>
这个错误可能是第一个 > 没有被转义,这取决于你如何将你的函数放在 XPage 上。
将函数移动到脚本库中,无论如何这是最佳实践。
或者使用 ScriptBlock 将其保留在页面上。要获得正确的格式,请将其添加到页面并通过属性粘贴您的脚本。如果您直接粘贴到源代码中,您可能会错过一个标签。
确保它是静态的,而不是计算的。
我在 xPage 中有以下代码来使用 gridx。当它出于某种原因运行时,它会将我的第二个装饰器函数中的 > 符号转换为 &,这会导致 javascript interpereter 抛出错误。谁能看出哪里出了问题?
<script>
require(
[
"gridx/Grid",
"dojo/store/Memory",
"gridx/modules/ColumnResizer",
"gridx/modules/NestedSort",
"gridx/modules/Filter",
"gridx/modules/Bar",
"gridx/core/model/cache/Sync",
"dojo/domReady!"
],
function(Grid, MemoryStore, Resizer, NestedSort, Filter, Bar, Cache)
{
var columns = [
{id: 'ownerName', field: 'OccupantName', name: 'Name', width: '150px'},
{id: 'propertyAddress', field: 'PropertyAddress', name: 'Property Name'},
{id: 'contactInfo1', field: 'ContactInfo1', name: 'Contact Information 1',
decorator: function(value)
{
try
{
if( typeof( value ) === "undefined" )
return "";
if( typeof( value ) === "string" )
return value;
myLen = value.toString().length;
// THIS WORKS FINE
if( myLen > 35 )
return value.join( "<br></br>" );
return "";
} catch (e)
{
console.error('error decorating date: ' );
}
}
},
{id: 'contactInfo2', field: 'ContactInfo2', name: 'Contact Information 2',
decorator: function(value)
{
try
{
if( typeof( value ) === "undefined" )
return "";
if( typeof( value ) === "string" )
return value;
myLen = value.toString().length;
// THIS GETS TRANSLATED TO >
if( myLen > 35 )
return value.join( "<br></br>" );
return "";
} catch (e)
{
console.error('error decorating date: ' );
}
}
},
{id: 'myTier', field: 'MyTier', name: 'Tier'},
{id: 'my', field: 'MyFloor', name: 'Floor'}
];
// Make an AJAX call to look up the full data set and store it locally for fast access
dojo.xhr.get({
url:"xpRestSTAROccupantInfo.xsp/gridDataSTAROccupantInfo",
handleAs:"json",
load: function(restData){
// Load the data into a local memory store
var store = new MemoryStore({
data: restData,
idProperty: '@noteid'
});
grid = new Grid({
id: "my_gridX",
cacheClass: Cache,
store: store,
autoHeight: true,
structure: columns,
barTop: [
"gridx/support/Summary",
"gridx/support/DropDownPager",
{pluginClass: "gridx/support/QuickFilter", style: 'text-align: right;'}
],
barBottom: [
"gridx/support/LinkSizer",
{pluginClass: "gridx/support/LinkPager", style: 'text-align: right;'}
],
sortInitialOrder: {colId: 'ownerName', descending: false},
modules: [
Resizer,
NestedSort,
Filter,
Bar
]
});
//Put it into the DOM tree.
grid.placeAt('gridX_Here');
grid.startup();
},
error: function(msg, args) {
console.error('Error loading grid data: ' + msg );
alert('There was an error loading the data: ' + msg);
}
});
});
</script>
这个错误可能是第一个 > 没有被转义,这取决于你如何将你的函数放在 XPage 上。
将函数移动到脚本库中,无论如何这是最佳实践。
或者使用 ScriptBlock 将其保留在页面上。要获得正确的格式,请将其添加到页面并通过属性粘贴您的脚本。如果您直接粘贴到源代码中,您可能会错过一个标签。
确保它是静态的,而不是计算的。