【问题标题】:Django and Extjs, how to use combo with jsonstoreDjango 和 Extjs,如何将组合与 jsonstore 一起使用
【发布时间】:2011-09-04 07:23:14
【问题描述】:

我想显示一个带有 JsonStore 的 extjs 组合 服务器端我使用python/Django。

所以,这是我的组合:

xtype: 'combo',
store: new Ext.data.JsonStore({
    url: 'get_peoples',
    root: 'data',
    totalProperty: 'total',
    fields: [
        {name: 'name', mapping: 'fields.name'},
        {name: 'subname', mapping: 'fields.subname'}
    ],
    autoLoad: true
}),
trigerAction: 'all'

和views.py服务器端:

def get_peoples(request):
    queryset = People.objects.all()    
    data = '{"total": %s, "%s": %s}' % \
        (queryset.count(), 'data', serializers.serialize('json', queryset))
    return HttpResponse(data, mimetype='application/json')

get_people 打电话给我

{"total": 1, "data": [{"pk": 1, "model": "myapp.people", "fields": {"name": "Paul", "subname": "Di Anno"}}

我认为我做得不对,因为我的组合没有显示任何项目

【问题讨论】:

    标签: django extjs jsonstore


    【解决方案1】:

    您需要向您的 ComboBox 添加 displayField 和 valueField 声明,以便它知道您商店中的哪些字段可用于任一角色。另外,不需要在 store 中设置 autoLoad。

    new Ext.form.ComboBox({
        xtype: 'combo',
        store: new Ext.data.JsonStore({
            url: 'get_peoples',
            root: 'data',
            totalProperty: 'total',
            fields: [
                {name: 'name', mapping: 'fields.name'},
                {name: 'subname', mapping: 'fields.subname'}
            ]
        }),
        triggerAction: 'all',
    
        // Just guessing at the proper fields here.
        // Set them to whatever you wish.
        displayField: 'name',
        valueField: 'subname'
    });
    

    【讨论】:

      猜你喜欢
      • 2011-06-20
      • 2011-08-28
      • 2011-02-20
      • 2016-09-11
      • 2020-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-19
      相关资源
      最近更新 更多