简体   繁体   English

使用JSON对商店中的特定字段进行编码

[英]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: 目前,我可以使用商店,将其推送到数组中,并使用以下代码将其编码为JSON对象:

        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 您可以在此处找到有关JavaScript对象的一些文档

Or if you want to NOT push specific fields you can do this before pushing: 或者,如果您不想推送特定字段,则可以在推送之前执行此操作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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