2016-10-10 46 views
0

我有以下的mixin在JS /部件/ LoadAllStoreMixin.js声明:定制_StoreMixin为dGrid没有做它应该做的

define([ 'dojo/_base/declare', 'dgrid/_StoreMixin' ], function(declare, 
     _StoreMixin) { 
    return declare(_StoreMixin, { 
     // summary: 
     // dgrid mixin which implements the refresh method to 
     // always perform a single query with no start or count 
     // specified, to retrieve all relevant results at once. 
     // Appropriate for grids using memory stores with small 
     // result set sizes. 

     refresh : function() { 
      var self = this; 

      // First defer to List#refresh to clear the grid's 
      // previous content 
      this.inherited(arguments); 

      if (!this._renderedCollection) { 
       return; 
      } 

      return this._trackError(function() { 
       var queryResults = self._renderedCollection.fetch(); 
       queryResults.totalLength.then(function(total) { 
        // Record total so it can be retrieved later via 
        // get('total') 
        self._total = total; 
       }); 
       return self.renderQueryResults(queryResults); 
      }); 
     }, 

     renderArray : function() { 
      var rows = this.inherited(arguments); 

      // Clear _lastCollection which is ordinarily only used for 
      // store-less grids 
      this._lastCollection = null; 

      return rows; 
     } 
    }); 
}); 

这是写在http://dgrid.io/tutorials/0.4/single_query/允许的OnDemandList相同的部件加载一切,而不是只有minRowsPerPage记录。它被称为是这样的:

var gridDataString = dom.byId("connectedEnvironmentsAndLevelsGridData").innerHTML; 
eval("var connectedEnvironmentsAndLevelsGridJsonData=" + gridDataString); 
var connectedEnvironmentsAndLevelsStore = new Memory( 
     { data: connectedEnvironmentsAndLevelsGridJsonData } 
    ); 
var SelectionGrid = declare([ Grid, LoadAllStoreMixin, Selection, Keyboard, DijitRegistry]); 
connectedEnvironmentsAndLevelsGrid = new SelectionGrid({ 
    store : connectedEnvironmentsAndLevelsStore, 
    selectionMode : "toggle", 
    columns : connectedEnvironmentsAndLevelsGridHeader, 
    allowSelectAll : true, 
    allowSelect: function(row) { 
     // disable the grid's rows basing on the phase compatibility 
     // if true, the row selection is enabled, otherwise disabled 
     return checkPhaseCompatibility(row); 
    } 
}, "connectedEnvironmentsAndLevelsGrid"); 
// Grid is an OnDemandGrid, not a normal grid. 

它被正确加载(所以有与define([], function(){});样板没有问题),但由于某些原因,它在第一ifrefresh()返回,所以它不会做什么它应该。我不知道为什么这会失败。我是否需要编写更多的代码,而不仅仅是refresh()renderArray()函数?

回答

0

您使用的是dgrid 0.4版本的示例,我希望您也使用了相同版本的api。

在0.4版本中,那里的store财产已被更改为collection

connectedEnvironmentsAndLevelsGrid = new SelectionGrid({ 
    collection : connectedEnvironmentsAndLevelsStore, 
    selectionMode : "toggle", 
    columns : connectedEnvironmentsAndLevelsGridHeader, 
    allowSelectAll : true, 
    allowSelect: function(row) { 
     // disable the grid's rows basing on the phase compatibility 
     // if true, the row selection is enabled, otherwise disabled 
     return checkPhaseCompatibility(row); 
    } 
}, "connectedEnvironmentsAndLevelsGrid"); 

更新:如果您正在使用0.3version,例如在日文章将无法正常工作,因为没有_renderCollection财产_StoreMixin 0.3版。此外,其他属性也会丢失,如正在此扩展中使用的“_total”。

如果您可以让我们知道您正在努力实现的目标,那么我们可以提供替代解决方案。

+0

我实际上不确定我使用的是什么版本的dgrid。如果它还没有收集,它可能早于0.4。这是Dojo 1.8的版本。我们无法轻易改变这个版本,所以我可能需要一个来自Dojo 1.8附带的dgrid版本的例子。 – Nzall

+0

我检查了changeLog。我们使用的是dGrid 0.3.14。 – Nzall

+0

@Nzall用更多信息更新了帖子。 –

相关问题