2012-04-07 41 views
2

是否有比可以連接到Dojo商店的DataGrid更簡單的列表類型?dojo的簡單商店連接列表

我想要商店的數據抽象,但我不需要頭和單元結構。我希望在數據庫的表示方面更加靈活,在這裏可能每行都會調用一個函數來進行佈局...

回答

2

你問一個非常好的問題。我實際上有一篇博客文章仍然處於草稿形式,名爲「DataGrid不應該是您的第一個選項」。

我已經做了一些事情,使用商店以重複的形式顯示商店的數據。

我已經手動構建一個html表使用dom構造和每個。

var table = dojo.create('table', {}, parentNode); 
var tbody = dojo.create('tbody', {}, table); // a version of IE needs this or it won't render the table 

store.fetch({ // this is a dojo.data.ItemFileReadStore, but you cana dapt to the dojo.Store API 
    query: {}, 
    onComplete: function(itms) { 
     dojo.forEach(itms, function(itm, idx) { 
      var tr = dojo.create('tr', {}, tbody); 
      // use idx to set odd/even css class 
      // create tds and the data that goes in them 
     }); 
    } 
}); 

我也創建了一箇中繼器,其中我有一個字符串形式的html模板,並使用它來實例化每行的html。

var htmlTemplate = '<div>${name}</div>'; // assumes name is in the data item 
store.fetch({ // this is a dojo.data.ItemFileReadStore, but you cana dapt to the dojo.Store API 
    query: {}, 
    onComplete: function(itms) { 
     dojo.forEach(itms, function(itm, idx) { 
      var expandedHtml = dojo.replace(htmlTemplate, itm); 
      // use dojo.place to put the html where you want it 
     }); 
    } 
}); 

您還可以爲每個項目實例化一個小部件。

+0

我有一個不同的博客帖子的一部分,這也證明了這一點。在底部,有一個fnDisplayOrders函數可以完成上述的一些操作。 https://gist.github.com/2010137 – 2012-04-07 15:55:23

+0

是的,我想我需要訴諸這樣的解決方案。儘管如此,我認爲dojo擁有所有這些抽象商店,然後缺少小部件來使用它們,這有點奇怪。 – RickyA 2012-04-07 20:47:43