简体   繁体   中英

Encode specific fields from store in JSON

Currently I can take a store, push it into an array, and encode it to a JSON object with this:

        var models = msgLogStore.getRange(),
            tmpArray = [];

        for (m = 0; m < models.length; m++) {
            tmpArray.push(models[m].data);
        }

        var msgLogDataAsJson = Ext.JSON.encode(tmpArray);

But how would I go about only pushing specific fields?

You would do this to push the field you want:

tmpArray.push(models[m].data["myField"]);

OR

tmpArray.push(models[m].data.myField);

You can find some doc on JavaScript objects here

Or if you want to NOT push specific fields you can do this before pushing:

models[m].data["unwantedField"] = undefined;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM