Funky IE JSON conversions - json
When running our AngularJS app in IE11 everything looks great in the debugger, but when our app encodes the data as JSON to save to our database, we get bad results.
Our app obtains a record from our database, then some manipulation is done and then the data is saved back to the server from another model.
Here is the data I got back from the server in the setAttendanceGetSInfo() function below:
{"data":{"Start":"2014-10-16T19:36:00Z","End":"2014-10-16T19:37:00Z"},
This is the code used to "convert the data" to 3 properties in our model:
var setAttendanceGetSInfo = function (CourseId, PID) {
return setAttendanceInfo(CourseId, PID)
.then(function (result) {
return $q.all([
$http.get("../api/Axtra/getSInfo/" + model.event.Id),
$http.get("../api/Axtra/GetStartAndEndDateTime/" + aRow.Rid)
]);
}).then(function (result) {
var r = result.data;
var e = Date.fromISO(r.Start);
var f = Date.fromISO(r.End);
angular.extend(model.event, {
examDate: new Date(e).toLocaleDateString(),
examStartTime: (new Date(e)).toLocaleTimeString(),
examEndTime: (new Date(f)).toLocaleTimeString()
});
return result.sInfo;
});
};
fromISO is defined as:
(function(){
var D= new Date('2011-06-02T09:34:29+02:00');
if(!D || +D!== 1307000069000){
Date.fromISO= function(s){
var day, tz,
rx=/^(\d{4}\-\d\d\-\d\d([tT ][\d:\.]*)?)([zZ]|([+\-])(\d\d):(\d\d))?$/,
p= rx.exec(s) || [];
if(p[1]){
day= p[1].split(/\D/);
for(var i= 0, L= day.length; i<L; i++){
day[i]= parseInt(day[i], 10) || 0;
};
day[1]-= 1;
day= new Date(Date.UTC.apply(Date, day));
if(!day.getDate()) return NaN;
if(p[5]){
tz= (parseInt(p[5], 10)*60);
if(p[6]) tz+= parseInt(p[6], 10);
if(p[4]== '+') tz*= -1;
if(tz) day.setUTCMinutes(day.getUTCMinutes()+ tz);
}
return day;
}
return NaN;
}
}
else{
Date.fromISO= function(s){
return new Date(s);
}
}
})()
Take a look at the screenshot of the event model data:
But, if I eval the event model using JSON.stringify(model.event), I get this:
{\"examDate\":\"?10?/?16?/?2014\",\"examStartTime\":\"?2?:?44?:?00? ?PM\",\"examEndTime\":\"?2?:?44?:?00? ?PM\"}
And this is the JSON encoded data that actually got stored on the DB:
"examDate":"¿10¿/¿16¿/¿2014","examStartTime":"¿2¿:¿36¿:¿00¿ ¿PM","examEndTime":"¿2¿:¿37¿:¿00¿ ¿PM"
What is wrong here and how can I fix this? It works exactly as designed in Chrome and Firefox. I have not yet tested on Safari or earlier versions of IE.
The toJSON for the date class isn't defined perfectly the same for all browsers.
(You can see a related question here: Discrepancy in JSON.stringify of date values in different browsers
I would suspect that you have a custom toJSON added to the Date prototype since your date string doesn't match the standard and that is likely where your issue is. Alternatively, you can use the Date toJSON recommended in the above post to solve your issues.
First, I modified the fromISO prototype to this:
(function () {
var D = new Date('2011-06-02T09:34:29+02:00');
if (!D || +D !== 1307000069000) {
Date.fromISO = function (s) {
var D, M = [], hm, min = 0, d2,
Rx = /([\d:]+)(\.\d+)?(Z|(([+\-])(\d\d):(\d\d))?)?$/;
D = s.substring(0, 10).split('-');
if (s.length > 11) {
M = s.substring(11).match(Rx) || [];
if (M[1]) D = D.concat(M[1].split(':'));
if (M[2]) D.push(Math.round(M[2] * 1000));// msec
}
for (var i = 0, L = D.length; i < L; i++) {
D[i] = parseInt(D[i], 10);
}
D[1] -= 1;
while (D.length < 6) D.push(0);
if (M[4]) {
min = parseInt(M[6]) * 60 + parseInt(M[7], 10);// timezone not UTC
if (M[5] == '+') min *= -1;
}
try {
d2 = Date.fromUTCArray(D);
if (min) d2.setUTCMinutes(d2.getUTCMinutes() + min);
}
catch (er) {
// bad input
}
return d2;
}
}
else {
Date.fromISO = function (s) {
return new Date(s);
}
}
Date.fromUTCArray = function (A) {
var D = new Date;
while (A.length < 7) A.push(0);
var T = A.splice(3, A.length);
D.setUTCFullYear.apply(D, A);
D.setUTCHours.apply(D, T);
return D;
}
Date.toJSON = function (key) {
return isFinite(this.valueOf()) ?
this.getUTCFullYear() + '-' +
f(this.getUTCMonth() + 1) + '-' +
f(this.getUTCDate()) + 'T' +
f(this.getUTCHours()) + ':' +
f(this.getUTCMinutes()) + ':' +
f(this.getUTCSeconds()) + 'Z' : null;
};
})()
Then I added moment.js and formatted the dates when they get stored:
var SaveAffRow = function () {
// make sure dates on coursedate and event are correct.
var cd = model.a.courseDate;
var ed = model.event.examDate;
var est = model.event.examStartTime;
var eet = model.event.examEndTime;
model.a.courseDate = moment(cd).format("MM/DD/YYYY");
model.event.examDate = moment(ed).format("MM/DD/YYYY");
model.event.examStartTime = moment(est).format("MM/DD/YYYY hh:mm A");
model.event.examEndTime = moment(eet).format("MM/DD/YYYY hh:mm A");
affRow.DocumentsJson = angular.toJson({a: model.a, event: model.event});
var aff = {};
if (affRow.Id != 0)
aff = affRow.$update({ Id: affRow.Id });
else
aff = affRow.$save({ Id: affRow.Id });
return aff;
};
and when they get read (just in case they are messed up already):
var setAttendanceGetSInfo = function (CourseId, PID) {
return setAttendanceInfo(CourseId, PID)
.then(function (result) {
return $q.all([
$http.get("../api/Axtra/getSInfo/" + model.event.Id),
$http.get("../api/Axtra/GetStartAndEndDateTime/" + aRow.Rid)
]);
}).then(function (result) {
var r = result.data;
var e = Date.fromISO(r.Start);
var f = Date.fromISO(r.End);
angular.extend(model.event, {
examDate: moment(e).format("MM/DD/YYYY"),
examStartTime: moment(e).format("MM/DD/YYYY hh:mm A"),
examEndTime: moment(f).format("MM/DD/YYYY hh:mm A")
});
return result.sInfo;
});
};
Related
find all label and product in json python
I'm trying to find all label and product in text/javascript, but I don't have any idea to how do it. I'm trying to parse label, id and products. var spConfigDisabledProducts = [-1 , '290058', '290060', '290061', '290062', '290063', '290065', '290071', '290073', '290075', '290076', '290077', '290078' ]; var spConfig = new Product.Config({"attributes":{"959":{"id":"959","code":"aw_taglia","label":"Taglia","options":[{"id":"730","label":"36 ½","price":"0","oldPrice":"0","products":["290058"]},{"id":"731","label":"37 ½","price":"0","oldPrice":"0","products":["290060"]},{"id":"732","label":"38","price":"0","oldPrice":"0","products":["290061"]},{"id":"733","label":"38 ½","price":"0","oldPrice":"0","products":["290062"]},{"id":"734","label":"39","price":"0","oldPrice":"0","products":["290063"]},{"id":"735","label":"40","price":"0","oldPrice":"0","products":["290064"]},{"id":"736","label":"40 ½","price":"0","oldPrice":"0","products":["290065"]},{"id":"737","label":"41","price":"0","oldPrice":"0","products":["290066"]},{"id":"738","label":"42","price":"0","oldPrice":"0","products":["290067"]},{"id":"739","label":"42 ½","price":"0","oldPrice":"0","products":["290068"]},{"id":"740","label":"43","price":"0","oldPrice":"0","products":["290069"]},{"id":"741","label":"44","price":"0","oldPrice":"0","products":["290070"]},{"id":"742","label":"44 ½","price":"0","oldPrice":"0","products":["290071"]},{"id":"743","label":"45","price":"0","oldPrice":"0","products":["290072"]},{"id":"744","label":"45 ½","price":"0","oldPrice":"0","products":["290073"]},{"id":"745","label":"46","price":"0","oldPrice":"0","products":["290074"]},{"id":"746","label":"47","price":"0","oldPrice":"0","products":["290075"]},{"id":"747","label":"47 ½","price":"0","oldPrice":"0","products":["290076"]},{"id":"748","label":"13.5","price":"0","oldPrice":"0","products":["290077"]},{"id":"749","label":"48 ½","price":"0","oldPrice":"0","products":["290078"]}]}},"template":"#{price}\u00a0\u20ac","basePrice":"130","oldPrice":"130","productId":"290059","chooseText":"Seleziona","taxConfig":{"includeTax":true,"showIncludeTax":true,"showBothPrices":false,"defaultTax":0,"currentTax":0,"inclTaxTitle":"Incl. Tasse"}}); jQuery("#attribute959 option").each(function () { var option = jQuery(this); var id = option.attr('value'); jQuery.each(spConfig.config.attributes, function () { jQuery.each(this.options, function () { if (this.id == id) { if (spConfigDisabledProducts.indexOf(this.products[0]) >= 0) { option.data('disabled', true); } } }); }); });
It's possible to do that less elegantly but without regex - just a series of splits and clean ups: import json code = [your script above] code2 = html.replace('½','').split('":"Taglia","options":[{')[1].split('}]}},"template"')[0].split('},{') for i in range(len(code2)): data = json.loads('{'+code2[i]+'}') print(data['id'],data['label']) Output: 730 36 731 37 732 38 733 38 etc.
You can regex out javascript object and pass to json then parse out info import re import json #html = response.content from requests html = ''' var spConfigDisabledProducts = [-1 , '290058', '290060', '290061', '290062', '290063', '290065', '290071', '290073', '290075', '290076', '290077', '290078' ]; var spConfig = new Product.Config({"attributes":{"959":{"id":"959","code":"aw_taglia","label":"Taglia","options":[{"id":"730","label":"36 ½","price":"0","oldPrice":"0","products":["290058"]},{"id":"731","label":"37 ½","price":"0","oldPrice":"0","products":["290060"]},{"id":"732","label":"38","price":"0","oldPrice":"0","products":["290061"]},{"id":"733","label":"38 ½","price":"0","oldPrice":"0","products":["290062"]},{"id":"734","label":"39","price":"0","oldPrice":"0","products":["290063"]},{"id":"735","label":"40","price":"0","oldPrice":"0","products":["290064"]},{"id":"736","label":"40 ½","price":"0","oldPrice":"0","products":["290065"]},{"id":"737","label":"41","price":"0","oldPrice":"0","products":["290066"]},{"id":"738","label":"42","price":"0","oldPrice":"0","products":["290067"]},{"id":"739","label":"42 ½","price":"0","oldPrice":"0","products":["290068"]},{"id":"740","label":"43","price":"0","oldPrice":"0","products":["290069"]},{"id":"741","label":"44","price":"0","oldPrice":"0","products":["290070"]},{"id":"742","label":"44 ½","price":"0","oldPrice":"0","products":["290071"]},{"id":"743","label":"45","price":"0","oldPrice":"0","products":["290072"]},{"id":"744","label":"45 ½","price":"0","oldPrice":"0","products":["290073"]},{"id":"745","label":"46","price":"0","oldPrice":"0","products":["290074"]},{"id":"746","label":"47","price":"0","oldPrice":"0","products":["290075"]},{"id":"747","label":"47 ½","price":"0","oldPrice":"0","products":["290076"]},{"id":"748","label":"13.5","price":"0","oldPrice":"0","products":["290077"]},{"id":"749","label":"48 ½","price":"0","oldPrice":"0","products":["290078"]}]}},"template":"#{price}\u00a0\u20ac","basePrice":"130","oldPrice":"130","productId":"290059","chooseText":"Seleziona","taxConfig":{"includeTax":true,"showIncludeTax":true,"showBothPrices":false,"defaultTax":0,"currentTax":0,"inclTaxTitle":"Incl. Tasse"}}); jQuery("#attribute959 option").each(function () { var option = jQuery(this); var id = option.attr('value'); jQuery.each(spConfig.config.attributes, function () { jQuery.each(this.options, function () { if (this.id == id) { if (spConfigDisabledProducts.indexOf(this.products[0]) >= 0) { option.data('disabled', true); } } }); }); });''' p = re.compile(r'Product\.Config\((.*?)\)', re.DOTALL) data = json.loads(p.findall(html)[0]) for attribute in data['attributes']: print('-----------------attribute--------------') print('label = ' + data['attributes'][attribute]['label'], 'id = ' + data['attributes'][attribute]['id']) print('-----------------options----------------') for product in data['attributes'][attribute]['options']: print('label = ' + product['label'], 'id = ' + product['id'], 'product = ' + product['products'][0])
Alexa (Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', got 'undefined')
My code is not working when I test it in Amazon Developer and I don't see anything wrong with my code. It says my response is invalid. Here's the code I tried to run but failed(I ran one response but not the other): var Alexa = require('alexa-sdk'); exports.handler = function(event, context, callback) { var alexa = Alexa.handler(event, context); // alexa.dynamoDBTableName = 'YourTableName'; // creates new table for userid:session.attributes alexa.registerHandlers(handlers); alexa.execute(); }; var handlers = { 'LaunchRequest': function () { this.emit('WelcomeIntent'); }, 'WelcomeIntent': function () { this.emit(':ask', 'Welcome to the guessing game! What difficulty would you like to play? Easy, Medium, or Hard?'); }, //------------------------------------------------------------------------------------------------------------------------------------------------ 'DifficultyIntent': function (){ var difficulty = this.event.request.intent.slots.difficulty.value; var range = 10; this.attributes['RandomNumberEnd'] = range; if (difficulty === 'easy') { range = 10; this.emit[':ask Your range is 1 - ' + range] } else if (difficulty === 'medium') { range = 100; this.emit[':ask Your range is 1 - ' + range] } else (difficulty === 'hard'); { range = 1000; this.emit[':ask Your range is 1 - ' + range] } var randomNumber = Math.floor((Math.random()*range)+1); var rightAnswer = this.attributes['rightAnswer'] = rightAnswer; }, //check the user's guess with the right answer 'UserGuessIntent': function (){ var guess = this.event.request.intent.slots.guess.value; this.attributes['guess'] = guess; this.emit('CheckIntent'); }, 'CheckIntent': function (){ var guess = this.attributes['guess']; this.attributes['rightAnswer'] = randomNumber; if(guess < rightAnswer){ this.emit(':ask', 'Try Again! Guess higher!'); } else if(guess > rightAnswer) {this.emit(':ask', 'Try Again! Guess lower!'); } else{ this.emit(':tell', 'You are correct! Congratulations!'); } }, 'QuitIntent': function(){ var stop = this.event.request.intent.slots.stop.value; this.emit('AMAZON.StopIntent'); }, 'AMAZON.StopIntent' : function(){ var rightAnswer = this.attributes['rightAnswer']; this.emit(':tell', 'The right answer is ' + rightAnswer + '. Goodbye!'); } };
Progressbar in angular
I want to make Progressbar in Angular.js in decimal format, simple format, times based Progressbar. Someone could pls help ! E.g. Start Timer {{ counter }}/{{ max }} = {{ (counter/max)*100 }}% Start Timer 20/30 = 66.66666666666666% Here is example.js: angular.module('plunker', ['ui.bootstrap']); var ProgressDemoCtrl = function ($scope) { $scope.max = 200; $scope.random = function () { var value = Math.floor((Math.random() * 100) + 1); var type; if (value < 25) { type = 'success'; } else if (value < 50) { type = 'info'; } else if (value < 75) { type = 'warning'; } else { type = 'danger'; } $scope.showWarning = (type === 'danger' || type === 'warning'); $scope.dynamic = value; $scope.type = type; }; var app = angular.module('plunker', ['ui.bootstrap']); app.controller('ProgressDemoCtrl', function ($scope) { $scope.value = 40; $scope.state = "progress-bar-success"; $scope.myStyle = {width: $scope.value + '%'}; }); $scope.random(); $scope.randomStacked = function() { $scope.stacked = []; var types = ['success', 'info', 'warning', 'danger']; for (var i = 0, n = Math.floor((Math.random() * 4) + 1); i < n; i++) { var index = Math.floor((Math.random() * 4)); $scope.stacked.push({ value: Math.floor((Math.random() * 30) + 1), type: types[index] }); } }; $scope.randomStacked(); }; var app = angular.module('progressApp',['nprogress']); var MainCtrl = function($scope,ngProgress){ }
I use this round progress ba directive, works pretty well: http://www.youtube.com/watch?v=w2qrYL0Le24 https://github.com/angular-directives/angular-round-progress-directive If you need a rectangular one give me a buzz I, have a custom directive implemented. If you need two decimal numbers you only have to adjust the font size. Test with two decimals: Code to change (configuring ang:roundprogress directive) data-round-progress-label-font="80pt Arial" Whole markup <div ang:round:progress data-round-progress-model="roundProgressData" data-round-progress-width="500" data-round-progress-height="500" data-round-progress-outer-circle-width="40" data-round-progress-inner-circle-width="10" data-round-progress-outer-circle-radius="200" data-round-progress-inner-circle-radius="140" data-round-progress-label-font="80pt Arial" data-round-progress-outer-circle-background-color="#505769" data-round-progress-outer-circle-foreground-color="#12eeb9" data-round-progress-inner-circle-color="#505769" data-round-progress-label-color="#fff"></div>
Can I increase QUOTA_BYTES_PER_ITEM in Chrome?
Is there any way to increase the chrome.storage.sync.QUOTA_BYTES_PER_ITEM ? For me, the default 4096 Bytes is a little bit short. I tried to execute chrome.storage.sync.QUOTA_BYTES_PER_ITEM = 8192; However, it seems that the actual limit doesn't change. How can I do this?
No, QUOTA_BYTES_PER_ITEM is there for reference only; it is not a settable value. You could use the value of QUOTA_BYTES_PER_ITEM to split an item up into multiple items, though: function syncStore(key, objectToStore, callback) { var jsonstr = JSON.stringify(objectToStore); var i = 0; var storageObj = {}; // split jsonstr into chunks and store them in an object indexed by `key_i` while(jsonstr.length > 0) { var index = key + "_" + i++; // since the key uses up some per-item quota, see how much is left for the value // also trim off 2 for quotes added by storage-time `stringify` var valueLength = chrome.storage.sync.QUOTA_BYTES_PER_ITEM - index.length - 2; // trim down segment so it will be small enough even when run through `JSON.stringify` again at storage time var segment = jsonstr.substr(0, valueLength); while(JSON.stringify(segment).length > valueLength) segment = jsonstr.substr(0, --valueLength); storageObj[index] = segment; jsonstr = jsonstr.substr(valueLength); } // store all the chunks chrome.storage.sync.set(storageObj, callback); } Then write an analogous fetch function that fetches by key and glues the object back together.
just modify answer of #apsilliers function syncStore(key, objectToStore) { var jsonstr = JSON.stringify(objectToStore); var i = 0; var storageObj = {}; // split jsonstr into chunks and store them in an object indexed by `key_i` while(jsonstr.length > 0) { var index = key + "_" + i++; // since the key uses up some per-item quota, see how much is left for the value // also trim off 2 for quotes added by storage-time `stringify` const maxLength = chrome.storage.sync.QUOTA_BYTES_PER_ITEM - index.length - 2; var valueLength = jsonstr.length; if(valueLength > maxLength){ valueLength = maxLength; } // trim down segment so it will be small enough even when run through `JSON.stringify` again at storage time //max try is QUOTA_BYTES_PER_ITEM to avoid infinite loop var segment = jsonstr.substr(0, valueLength); for(let i = 0; i < chrome.storage.sync.QUOTA_BYTES_PER_ITEM; i++){ const jsonLength = JSON.stringify(segment).length; if(jsonLength > maxLength){ segment = jsonstr.substr(0, --valueLength); }else { break; } } storageObj[index] = segment; jsonstr = jsonstr.substr(valueLength); } also function to read each partition and merge again function syncGet(key, callback) { chrome.storage.sync.get(key, (data) => { console.log(data[key]); console.log(typeof data[key]); if(data != undefined && data != "undefined" && data != {} && data[key] != undefined && data[key] != "undefined"){ const keyArr = new Array(); for(let i = 0; i <= data[key].count; i++) { keyArr.push(`${data[key].prefix}${i}`) } chrome.storage.sync.get(keyArr, (items) => { console.log(data) const keys = Object.keys( items ); const length = keys.length; let results = ""; if(length > 0){ const sepPos = keys[0].lastIndexOf("_"); const prefix = keys[0].substring(0, sepPos); for(let x = 0; x < length; x ++){ results += items[`${prefix }_${x}`]; } callback(JSON.parse(results)); return; } callback(undefined); }); } else { callback(undefined); } }); } it tested and it works for my case
this is a better version of #uncle bob's functions, working with manifest v3 (you can use it just like how you can use the normal sync.set or sync.get function) NOTE: it only works with JSONs (arrays and objects) since a string shouldn't be that long let browserServices; if (typeof browser === "undefined") { browserServices = chrome; } else { browserServices = browser; } function syncSet(obj = {}) { return new Promise((resolve, reject) => { var storageObj = {}; for (let u = 0; u < Object.keys(obj).length; u++) { const key = Object.keys(obj)[u]; const objectToStore = obj[key] var jsonstr = JSON.stringify(objectToStore); var i = 0; // split jsonstr into chunks and store them in an object indexed by `key_i` while (jsonstr.length > 0) { var index = key + "USEDTOSEPERATE" + i++; // since the key uses up some per-item quota, see how much is left for the value // also trim off 2 for quotes added by storage-time `stringify` const maxLength = browserServices.storage.sync.QUOTA_BYTES_PER_ITEM - index.length - 2; var valueLength = jsonstr.length; if (valueLength > maxLength) { valueLength = maxLength; } // trim down segment so it will be small enough even when run through `JSON.stringify` again at storage time //max try is QUOTA_BYTES_PER_ITEM to avoid infinite loop var segment = jsonstr.substring(0, valueLength); var jsonLength = JSON.stringify(segment).length; segment = jsonstr.substring(0, valueLength = (valueLength - (jsonLength - maxLength) - 1)); for (let i = 0; i < browserServices.storage.sync.QUOTA_BYTES_PER_ITEM; i++) { jsonLength = JSON.stringify(segment).length; if (jsonLength > maxLength) { segment = jsonstr.substring(0, --valueLength); } else { break; } } storageObj[index] = segment; jsonstr = jsonstr.substring(valueLength, Infinity); } } chrome.storage.sync.set(storageObj).then(() => { resolve() }) }) } function syncGet(uniqueKeys = []) { return new Promise((resolve, reject) => { browserServices.storage.sync.get(null).then((data) => { const keyArr = Object.keys(data).filter(e => uniqueKeys.filter(j => e.indexOf(j) == 0).length > 0) browserServices.storage.sync.get(keyArr).then((items) => { var results = {}; for (let i = 0; i < uniqueKeys.length; i++) { const uniqueKey = uniqueKeys[i]; const keysFiltered = keyArr.filter(e => e.split("USEDTOSEPERATE")[0] == uniqueKey) if (keysFiltered.length > 0) { results[uniqueKey] = "" for (let x = 0; x < keysFiltered.length; x++) { results[uniqueKey] += items[`${keysFiltered[x]}`]; } results[uniqueKey] = JSON.parse(results[uniqueKey]) } } resolve(results) }); }); }) } example of usage: syncSet({ "keyTest": ["a lot of text"], "keyTest1": ["a lot of text"] } ) syncGet(["keyTest","keyTest1"]).then(results=>console.log(results)) // {keyTest:["a lot of text"],keyTest1:["a lot of text"]}
json not matching model
In EXTJS i will use a model and store for my grid. Now is the problem that sometimes the json will not match the model. There will be less information then in my model. When this happens EXTJS will not show any data in the grid. So i looked for a fix and found this: Ext.define('App.Reader', { extend: 'Ext.data.reader.Json', extractData: function(root) { var me = this, values = [], records = [], Model = me.model, i = 0, length = root.length, idProp = me.getIdProperty(), node, id, record; if (!root.length && Ext.isObject(root)) { root = [root]; length = 1; } for (; i < length; i++) { node = root[i]; values = me.extractValues(node); id = me.getId(node); record = new Model(values, id, node); records.push(record); if (me.implicitIncludes) { me.readAssociated(record, node); } } return records; }, extractValues: function(data) { var fields = this.getFields(), i = 0, length = fields.length, output = {}, field, value; for (; i < length; i++) { field = fields[i]; value = this.extractorFunctions[i](data); if(value === undefined) { Ext.iterate(fields, function(key, val) { if (data[key] === undefined & i==val) { console.log( "Model field <" + key.name + "> does not exist in data/node."); value = "INVALID OR MISSING FIELD NAME"; var p = 0; for(var prop in data) { if(p==i){ if(data.hasOwnProperty(prop))console.log("Instead of <" + key.name + "> we have <" + prop + "> with value <" + data[prop]+ ">"); } p++; } } }, this); } output[field.name] = value; } return output; } }); var myReader = new App.Reader({ type:'json' }); i found this online. But when i use this with EXTJS 4.1.1 there is an error in ext-all: TypeError: j is undefined. Where should i look for the fix for this?
There's no need to do something complicated to solve this trivial problem. Read up on Ext.data.Model and Ext.data.Field, configure your Model properly and you're all set.