简体   繁体   English

xPages中的Javascript错误

[英]Javascript in xPages error

I have the following code in an xPage to use gridx. 我在xPage中有以下代码以使用gridx。 When it runs for some reason it translates the > symbol in my second decorator function to & which causes the javascript interpereter to throw and error. 当它由于某种原因运行时,它将我第二个装饰器函数中的>符号转换为&,从而导致javascript互操作器抛出错误。 Can anyone see what is wrong? 谁能看到错在哪里?

<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 &gt;
                    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>

The bug might be the first > not being escaped, depending how you did put your function on the XPage. 该错误可能是第一个>无法幸免的错误,具体取决于您将函数放在XPage上的方式。

Move the function into a script library, which is best Practise anyway. 将该函数移到脚本库中,无论如何还是最佳实践。

Alternative use an ScriptBlock to keep it on the page. 或者使用ScriptBlock将其保留在页面上。 To get the format right add it to the page and paste your script through the properties. 要获得正确的格式,请将其添加到页面并通过属性粘贴您的脚本。 If you go for pasting into the source directly you might miss a tag. 如果您直接粘贴到源代码中,则可能会丢失标签。

Make sure it is static, not computed. 确保它是静态的,而不是计算的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM