dojo的简单商店连接列表

时间:2012-04-07 14:44:59

标签: dojo

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

我想要商店的数据抽象,但我不需要标题和单元格结构。我希望在数据线的表示方面更灵活,可能每一行都调用一个函数来布局......

1 个答案:

答案 0 :(得分: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
        });
    }
});

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

相关问题