4

I am trying to get value from nested json, but unable to get value. I have following data structure. Here I am printing record.

enter image description here

What i did.

 onWordTap: function(view, index, target, record, event) {
        var wordName=record.get('name');
        console.log("Word--->>>>"+wordName);
        console.log(record);
    },

but i get in console like this:-> Word--->>>>undefined

I have tried this also:

var wordName=record.data.get('name');

but getting

Uncaught TypeError: Object # has no method 'get'

my JSON looks like this: JSON

My previous question is also related to this type question, please watch . Previous Problem

Community
  • 1
  • 1

3 Answers3

2

I am assuming this is a DataView or a List, and that onWordTap is a listener for for itemtap.

If that is the case, to get data from records, you just need record.get('name'). You can also use record.get('definitions')[0].definition (note that you've spelled it defintion in your code - beware).

kevhender
  • 4,285
  • 1
  • 13
  • 16
  • @ Kevhender, i too have same problem when i use record.get('name') it consoles undefined. – surhidamatya Aug 26 '13 at 03:39
  • can you shed some light how can i make it dynamic? – surhidamatya Aug 26 '13 at 04:24
  • when i am using record.get('')[].definition it's giving Uncaught TypeError: Cannot read property '0' of undefined – surhidamatya Aug 26 '13 at 06:34
  • 1
    @sur007, I would have to see your code to diagnose anything. You should probably post a new question. – kevhender Aug 26 '13 at 11:10
  • Can you look onto this, http://stackoverflow.com/questions/18125596/pass-argument-from-tpl-sencha – surhidamatya Aug 29 '13 at 05:36
  • Can you please please look on this i have watched http://www.kevhender.net/desktop/index.html this on mobile when orientation changes it doesnot restarts but my app restart can you please shed some light on it. I would be so thankful http://stackoverflow.com/questions/18372136/sencha-app-restarts-on-orientation-change – surhidamatya Aug 29 '13 at 05:55
  • 1
    Sorry @sur007, I've never had any problems with orientation changes, and I've never done anything special to address the issue... – kevhender Aug 29 '13 at 11:30
  • @ kevhender, it's ok. i think it's only problem when making android app not on web app. Thanks!!! – surhidamatya Oct 21 '13 at 06:08
1

your JSON contains array of data , so you need to access it with index. you can do it like this.

var wordName = record.data[0].get('name');
Deepak Patil
  • 285
  • 7
  • 23
  • 1
    This is wrong.if one name only i have get already like this: record.data.data[0].name; but i have multiple word and definition, in that time what can i do. any way thank you for your reply. –  Aug 23 '13 at 11:08
  • you can always loop it and get the value dude. you will get the length from the array , just put a loop on it and fetch the 'name' – Deepak Patil Aug 23 '13 at 11:30
  • 1
    thank you for reply, in loop it does not work. How to find which id holder word you have going to click. –  Aug 23 '13 at 12:16
1

It looks like you have a data property inside the data object. So it means sencha recognize the record as it has only one field actually called data. So, if im not wrong, what's the output of:

console.log(record.get('data'));

Also, please add the model associated to the store containing record.

Nico Grunfeld
  • 1,133
  • 1
  • 8
  • 19
  • 1
    console.log(record.get('data')); gives ---undefined--- output. I have not understand.but you can see my full model,store, view and controller associated question.http://stackoverflow.com/questions/18371402/unable-setting-nested-json-data-on-localstorage-in-sencha-touch –  Aug 27 '13 at 03:44
  • your answer sounds quite reasonable. console.log(record.get('data')); consoles undefined whereas console.log(record.data); consoles class of record as shown above in question and if we console.log(record.get(record.data.data)) it consoles data:Array[1] can be seen in above image.Thank You. – surhidamatya Aug 27 '13 at 05:34
  • @Nico Grunfeld Can you please take look onto this http://stackoverflow.com/questions/18125596/pass-argument-from-tpl-sencha – surhidamatya Aug 29 '13 at 05:29