0

我有以下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://

4

1 回答 1

2

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

于 2010-05-27T23:51:07.870 回答