How to add records in json-store

后端 未结 3 641
野的像风
野的像风 2021-02-01 09:24
var store = new Ext.data.JsonStore({
    id:\'jfields\',
    totalProperty:\'totalcount\',
    root:\'rows\',
    url: \'data.php\',  
    fields:[{ name:\'jfields\' },
         


        
相关标签:
3条回答
  • 2021-02-01 09:29

    I have also figured out a simple solution to this:

    listeners: {
        load: function( xstore ,  record , option ) {
            var u = new xstore.recordType({  jfields : 'monthly'  });
            xstore.insert(record.length, u);
        }
    }
    

    Here what I have to add is this listeners as when the data loads it will create the record type and u can add fields as data as many as u want

    0 讨论(0)
  • 2021-02-01 09:47

    See the recordType property in the JsonStore. It's a function that can be used as a record constructor for the store in question. Use it like this:

    var newRecord = new myStore.recordType(recordData, recordId);
    myStore.add(newRecord);
    
    0 讨论(0)
  • 2021-02-01 09:52

    You need to define a record type, create it and at it, e.g:

    TaskLocation = Ext.data.Record.create([
        {name: "id", type: "string"},
        {name: "type", type: "string"},
        {name: "type_data", type: "string"},
        {name: "display_value", type: "string"}
    ]);
    

    Then:

    var record = new TaskLocation({
        id: Ext.id(),
        type: "city",
        type_data: "",
        display_value: "Brighton"
    });
    

    Then:

    my_store.add(record);
    my_store.commitChanges();
    

    Remember by the time the data is in the store it's not in the same format as you sent it down but in Record objects instead.

    0 讨论(0)
提交回复
热议问题