2013-02-08 103 views
2

產生我有一個簡單的類包裝,我已經把一個模塊的命名組件內的網格​​控件類的一個實例,當我在Firefox 14.0.1測試它我得到:火狐不能與打字稿

類型錯誤:Components.Grid是不是構造@http:// ...

這裏通過打字稿生成的代碼:

var Components; 
(function (Components) { 
    Components.gridDefaults = { 
     datatype: "json", 
     autowidth: true, 
     rowNum: 30, 
     rowList: [ 
      10, 
      20, 
      30 
     ], 
     viewrecords: true, 
     sortorder: "asc", 
     pager: "#grid-pager" 
    }; 
    var Grid = (function() { 
     function Grid(selector, options) { 
      var opts = Components.gridDefaults; 
      if(options !== undefined && options !== null) { 
       $.extend(opts, options); 
      } 
      this.grid = $(selector).jqGrid(opts); 
     } 
     Grid.prototype.setToolbar = function (options) { 
      var pager = this.grid.getGridParam().pager; 
      if(pager !== undefined && pager !== null) { 
       this.grid.navGrid(pager, options); 
      } 
      return this; 
     }; 
     Grid.prototype.jqGrid = function() { 
      return this.grid; 
     }; 
     Grid.prototype.filter = function (criteria) { 
      this.grid.setGridParam({ 
       page: 1, 
       postData: criteria 
      }); 
      this.reload(); 
     }; 
     Grid.prototype.reload = function() { 
      this.grid.trigger("reloadGrid"); 
     }; 
     return Grid; 
    })(); 
    Components.Grid = Grid;  
})(Components || (Components = {})); 

//@ sourceMappingURL=grid-component.js.map 

這裏行了火狐抱怨缺乏一個構造函數:

var grid = new Components.Grid("#grid-container", { 
      url: "/Home/Data", 
      colNames: ['Inv No', 'Date', 'Client', 'Amount', 'Tax', 'Total', 'Notes'], 
      colModel: [ 
       { name: 'id', index: 'id', width: 55 }, 
       { name: 'invdate', index: 'invdate', width: 90, jsonmap: "invdate" }, 
       { name: 'name', index: 'name asc, invdate', width: 100 }, 
       { name: 'amount', index: 'amount', width: 80, align: "right" }, 
       { name: 'tax', index: 'tax', width: 80, align: "right" }, 
       { name: 'total', index: 'total', width: 80, align: "right" }, 
       { name: 'note', index: 'note', width: 150, sortable: false } 
      ], 
      jsonReader: { 
       id: "id", 
       repeatitems: false 
      } 
     }); 

我想聽聽某人@TypeScript團隊的消息。

回答

8

我不在TypeScript團隊中,也沒有使用過它。但我相信這不是一個TypeScript問題。問題在於你試圖覆蓋Firefox包含的內容,即Components

如果改爲

var Comps; 
(function (Components) { // keep the local name or change to Comps, as you like 
    Components.gridDefaults = { 
    // ... 
})(Comps || (Comps = {})); 
var grid = new Comps.Grid("#grid-container", { /* ... */ }); 

我認爲這將更好地工作。

我認爲這意味着更改您的Typescript模塊名稱。但我對此一無所知。

+0

+1 - 就Firefox而言,組件實際上是一個保留字:https://developer.mozilla.org/en/docs/Components.utils.import – Fenton 2013-02-08 16:52:52

+0

Scott,感謝我帶走了另一個愚蠢的時刻... 你釘了它! – 2013-02-08 17:32:19