2

有没有比 DataGrid 更简单的列表类型可以连接到 Dojo 的商店?

我想要商店的数据抽象,但我不需要标题和单元格结构。我想在数据线的表示上更加灵活,也许每条线都调用一个函数来布局......

4

1 回答 1

2

你问了一个非常好的问题。实际上,我有一篇博客文章仍处于草稿形式,名为“DataGrid 不应该是您的第一选择”。

我使用商店做了几件事,以重复的形式显示商店中的数据。

我已经使用 dom-construct 和每个手动构建了一个 html 表。

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
        });
    }
});

您还可以有一个为每个项目实例化的小部件。

于 2012-04-07T15:44:22.520 回答