0

Is it possible to use the following data of a webapp source with a chrome extention?

var listConfig = {
        data: {"___focus":0,"model":{"instance":[{
"___italic":"false",
"status":"open",
"priority_code":"3 - Medium",
"number":"IM000000001",
"problem_status":"Open",
"open_time":"25/08/14 16:56:13",
"assignment":"MY GROUP",
},

I would like to check if the "status" contains "open" and "priority_code" contains "3 - Medium" and if they do contain these strings, beep a sound.

So can I use it like something like this?

listConfig.data.model.instance("status");
listConfig.data.model.instance("priority_code");
Kijewski
  • 25,517
  • 12
  • 101
  • 143
Michael
  • 13
  • 2

1 Answers1

0

Well, Chrome apps are just regular javascript apps with additional chrome API. You are asking about basis of javascript. You can't use listConfig.data.model.instance("status"); in this context because there's no such function "instance".

However you can just read property and check it's value:

if(listConfig.data.model.instance.status === 'open') ...

Or you can replace object "instance" with function "instance"

var listConfig = {
   "data": {
      //...
      "model": {
          // properties
          instance = function(property){
             if(this[property]){
                return this[property];
             }
             return null;
          }
      }
   }
}

I hope it helps.

Pawel Uchida-Psztyc
  • 3,735
  • 2
  • 20
  • 41
  • I would like to use listConfig.data.model.instance.status However, i would like to test this in jsfiddle. And does that work when multiple instances exist? – Michael Aug 25 '14 at 22:45
  • No, it does not work for multiple instances. This kind of object are rather static. There is however possibility to make a function object for all attributes of listConfig and use "new" keyword to instantiate new object. Then it may work for multiple instances. See http://stackoverflow.com/a/4778408/1127848 for more information. – Pawel Uchida-Psztyc Aug 27 '14 at 14:37