Extjs DataView ArrayStore问题

时间:2010-05-27 20:43:41

标签: extjs dataview

我有以下JS:

http://monobin.com/__m1c171c4e

和以下代码:

代码:

var tpl = new Ext.XTemplate(
    '<tpl for=".">',
        '<div class="thumb-wrap" id="{Name}">',
        '<div class="thumb"><img src="{ImageMedium}" title="{Name}"></div>',
        '<span class="x-editable">{Name}</span></div>',
    '</tpl>',
    '<div class="x-clear"></div>'
);

var store = new Ext.data.ArrayStore({
    fields: [{ name: 'name' }, { name: 'ImageMedium'}],
    data: res.data.SimilarArtists
});

var panel = new Ext.Panel({
    frame: true,
    width: 535,
    autoHeight: true,
    collapsible: true,
    layout: 'fit',
    title: 'Simple DataView (0 items selected)',
    items: new Ext.DataView({
        store: store,
        tpl: tpl,
        autoHeight: true,
        multiSelect: true,
        overClass: 'x-view-over',
        itemSelector: 'div.thumb-wrap',
        emptyText: 'No images to display',
        prepareData: function (data) {
            data.Name = Ext.util.Format.ellipsis(data.Name, 15);
            return data;
        },

        plugins: [
            new Ext.DataView.DragSelector(),
            new Ext.DataView.LabelEditor({ dataIndex: 'name' })
        ],

        listeners: {
            selectionchange: {
                fn: function (dv, nodes) {

                }
            }
        }
    })
});

将DataView绑定到res.data.SimilarArtists的子数组

但似乎没有发生任何事情?

prepareData甚至没有被调用?

我做错了什么?

w://

1 个答案:

答案 0 :(得分:2)

您链接的数据结构是JSON,而不是数组数据。请尝试切换到JsonStore。请注意,JsonStore预先配置了JsonReader和HttpProxy(远程数据源),用于从URL加载数据。如果您需要从本地数据加载JSON,那么您将必须使用JsonReader和MemoryProxy创建一个通用存储。

相关问题