PDA

View Full Version : Store is adding empty JSON string



13 Oct 2014, 1:19 AM
Hello,

i'd like to understand.
I have a store and i have a server which sends me the value to fill the store written in a JSON format.

what i do is store.add(jsonstringlist);

This works fine.
Sometimes the server answers with an empty list {[]}, because, correctly, there's nothing to add.

Btw, in such case, if i look into the store, i find the it has been added an empty JSON model.
when i do store.add(some-json-string), how could i be sure that JUST and ONLY the strings that matches the model will be added?

Clearly i'm expecting that if i try to add {[ ]}, it will not add anything.

carol.ext
13 Oct 2014, 8:55 AM
Looks like you are passing an object {} containing an array []. Looking at the source code, an object passed in ends up wrapped in an array , so {[]} becomes [{[]}]. Array length is 1, so an empty model is added.



add: function(arg) {
var me = this,
records,
length, isSorted;

...

// Accept both a single-argument array of records, or any number of record arguments
if (Ext.isArray(arg)) {
records = arg;
} else {
records = arguments;
}

13 Oct 2014, 2:12 PM
Thanks for the answer.

Btw, i still don't understand why it should add an empty model. I mean, the store uses a model, let's called, foo.
foo is defined to have three fields. "id", "something1" and "something2".

Suppose that i add an empty model. Ok.
Why it should appear in the store even if it cannot be validate?

when i do "add" is it automatically validated?

evant
13 Oct 2014, 2:40 PM
{[]}


The above isn't a valid JSON response, what is your server actually returning?

13 Oct 2014, 11:27 PM
Actually my server answers me with a message like


{
id: 1
list: [{id: 1234,
something1: foo ,
something2: foo
}]
}


Yes, you are right. I misplaced the parethesis. it's [{}] !
Sometimes it returns me an empty list. and then i have the problem above.