2011-05-29 52 views
0

我想顯示與JsonStore的extjs組合 服務器端我使用python/Django。Django和Extjs,如何使用組合與jsonstore

所以,這是我的組合:

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"}} 

我想我不正確,導致我的組合不顯示任何項目

回答

2

您需要將displayField和valueField聲明添加到您的ComboBox中,以便它知道您的存儲中哪些字段用於任一角色。另外,在商店中設置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' 
});