未捕获的TypeError:无法读取未定义的属性'formatter'

时间:2014-04-09 17:55:22

标签: javascript salesforce

当我尝试打开选项卡时,此错误出现在控制台中,并且网格也未加载。

以下是创建超链接的方法:

function genUrl(cellValue, rowId, rowData){
    return ("{!LEFT($CurrentPage.URL,FIND('/',$CurrentPage.URL,9))}" +rowData.siteId);
  }
  function genUrl4(cellValue, rowId, rowData){
    return ("{!LEFT($CurrentPage.URL,FIND('/',$CurrentPage.URL,9))}" + rowData.SiteActId);
  }
  function genUrl5(cellValue, rowId, rowData){
    return ("{!LEFT($CurrentPage.URL,FIND('/',$CurrentPage.URL,9))}" + rowData.AltSiteActId);
  }
  function urlTemplate6 () {
      return ({formatter:'dynamicLink',formatoptions:{url: genUrl6, target:"_blank"},
                        sorttype:"link", searchoptions:{sopt:['eq','bw','bn','cn','nc','ew','en']}});
  }
  function genUrl6(cellValue, rowId, rowData){
    return ("{!LEFT($CurrentPage.URL,FIND('/',$CurrentPage.URL,9))}" + "apex/CountryDetail?name="+rowData.AltSiteCountry);
  }

定义每列中的数据格式

cfg.colModel = [
      {name:'siteName',index:'siteName', template:urlTemplate()},
      {name:'SiteActName',index:'SiteActName',template:urlTemplate4()},
      {name:'FullrecTime',index:'FullrecTime',template:numberTemplate()},
      {name:'AltsiteName',index:'AltsiteName',template:urlTemplate5()},
          {name:'AltSiteBringUptime',index:'AltSiteBringUptime',template:integerTemplate()},
      {name:'AltSiteCountry',index:'AltSiteCountry',template:urlTemplate6()},

错误显示的方法

              // Common formatting options
              $.jgrid.formatter.integer.thousandsSeparator = ',';
              $.jgrid.formatter.number.thousandsSeparator = ',';
              $.jgrid.formatter.number.decimalSeparator = '.';
              $.jgrid.formatter.number.decimalPlaces = 0;
              $.jgrid.formatter.currency.thousandsSeparator = ',';
              $.jgrid.formatter.currency.decimalPlaces = 0;

              // set up some global variables for use across callbacks
              window.firstLoad = true;
              // The following two to be set when we start restoring saved column state
              window.myColumnsState;
              window.isColState = false;

              window.myDefaultSearch = 'cn';

              UserTableSettings.getTableCfg(cfg.storageItemName, function(result,event){
                if (event.status){
                  if (result != null) {
                    var savedColState = JSON.parse(result.tableCfg);
                    myColumnsState = restoreColumnState (cfg.colModel, savedColState);
                  } else {
                    myColumnsState = null;
                  }
                  isColState = typeof (myColumnsState) !== 'undefined' && myColumnsState !== null;
                  $(cfg.tableName).jqGrid({
                    datatype: "local",
                    sortable: true,
                    //index: cfg.index,
                    autowidth: true,
                    shrinkToFit: true,
                    ignoreCase: true,
                    pager:cfg.pager,
                    rownumbers: true,
                    viewrecords: true,
                    viewsortcols:[true,'horizontal',true],
                    gridview: true,
                    autoencode: true,
                    height:cfg.height,
                    caption: cfg.caption,
                    rowNum:cfg.initialRows,
                    rowList:[10,20,50,100,100000000],
                    page: isColState ? myColumnsState.page : 1,
                    search: isColState ? myColumnsState.search : false,
                    postData: isColState ? { filters: myColumnsState.filters } : {},
                    sortname: isColState ? myColumnsState.sortname : cfg.initialSort,
                    sortorder: isColState ? myColumnsState.sortorder : 'desc',
                    colNames: cfg.colNames,
                    colModel: cfg.colModel,
                    storageItemName: cfg.storageItemName, // Resilinc addition
                    loadComplete: function() {
                      $("option[value=100000000]").text('All');
                      if (firstLoad) {
                        firstLoad = false;
                        if (isColState) {
                          $(this).jqGrid("remapColumns", myColumnsState.permutation, true);
                        }
                      }
                      //saveColumnState.call($(this), $(this).jqGrid('getGridParam', 'storageItemName'), this.p.remapColumns);
                    },
                    resizeStop: function () {
                      saveColumnState.call($(this), $(this).jqGrid('getGridParam', 'storageItemName'), $(this)[0].p.remapColumns);
                    }
                  });

                  $(cfg.tableName).navGrid(cfg.pager,{edit:false,add:false,del:false,refresh:false},{},{},{},{multipleSearch:true,multipleGroup:true, showQuery: true});
                  $(cfg.tableName).filterToolbar({searchOperators : true});
                  $.extend(true, $.ui.multiselect, {
                    locale: {
                      addAll: 'Make all visible',
                      removeAll: 'Hide All',
                      itemsCount: 'Available Columns'
                    }
                  });
                  $(cfg.tableName).jqGrid('navButtonAdd', cfg.pager, {
                      caption: "Columns",
                      buttonicon: "ui-icon-calculator",
                      title: "Choose columns",
                      onClickButton: function () {
                          $(this).jqGrid('columnChooser',
                            {width: 550,
                             msel_opts: {dividerLocation: 0.5},
                             done: function (perm) {
                              if (perm) {
                                this.jqGrid("remapColumns", perm, true);
                                saveColumnState.call(this, this.jqGrid('getGridParam', 'storageItemName'), perm);
                              }
                             }
                            }
                          );
                          $("#colchooser_" + $.jgrid.jqID(this.id) + ' div.available>div.actions')
                              .prepend('<label style="float:left;position:relative;margin-left:0.6em;top:0.6em">Search:</label>');
                      }
                  });
                  $(cfg.tableName).jqGrid('navButtonAdd', cfg.pager, {
                          caption: "",
                          buttonicon: "ui-icon-closethick",
                          title: "Clear saved table settings",
                          onClickButton: function () {
                              removeObjectFromServerStorage(cfg.storageItemName);
                          }
                      });
                    if(typeof cfg.loadData !== 'undefined')
                     cfg.loadData();
                } else {
                  // add some code here to handle a failed JS Remoting call
                }
              }, {escape:false});

function integerTemplate () {
    return ({formatter: 'integer', align: 'right', sorttype: 'integer',
        searchoptions: { sopt: ['eq', 'ne', 'lt', 'le', 'gt', 'ge'] }});

2 个答案:

答案 0 :(得分:0)

这通常意味着为变量formatter定义了一个值。但是,您的代码包含几个使用它的地方,因此我们无法确定确切的问题。

看看调试器给你的那一行并从那里开始。

您是否附加了正确的javascript文件?您是否忘记为您尝试使用的变量设置值?当你遇到这类问题时,不断问自己这类问题。

答案 1 :(得分:0)

$.jgrid.formatter.integer.thousandsSeparator

当此行开始运行时,您获得Cannot read property 'formatter' of undefined。这意味着.formatter之前的表达式为undefined。该表达式为$.jgrid

因此,无论在$.jgrid处放置什么东西都是行不通的。这是您正在使用的图书馆吗?该库是否包含在页面中并正确加载?如果您可以加载该库,则可能会开始工作。