cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

How to using json basetype in custom widget and without using infotable(use json object which is returned from service....directly)

jlin-4
1-Visitor

How to using json basetype in custom widget and without using infotable(use json object which is returned from service....directly)

Steps:

1.Ready a custom widget and define the widget properties as following:

  xxx.ide.js=>

this.widgetProperties = function () {

    return {

      'name': 'custom widget',

      'description': 'custom widget.',

      'category': ['Common'],

      'properties': {

          'Data1': {

              'description' : 'data',

              'isBindingTarget': true,

              'isVisible': true,

              'baseType': 'JSON',//not using infotable

              'warnIfNotBoundAsTarget': false

          }   

      }

    };

  };

2. Using the json obj as following:

xxx.runtime.js=>

if (updatePropertyInfo.TargetProperty === "Data1") {

   //How to get json here???

}

2 REPLIES 2

Hi,

You can get the JSON object like this

if (updatePropertyInfo.TargetProperty === 'JSONData') {

            var json= {};

            if(updatePropertyInfo.RawDataFromInvoke!=undefined) {

                json = updatePropertyInfo.RawDataFromInvoke;

            }

          /* do whatever */

}

Be carefull, that piece of code is only working with a service that only return the JSON data.

Your navugator degugger is your friend, I always verify with the content of the updatePropertyInfo variable.

It's content change if you're passing a singleProperty or an infotable.

Hope it's help.

Regards

Be careful,

If your widget is binded to an infotable JSON property, composer give you the entire infotable, I don't understand why.

It's seems to be a bug.

In that case I retrive the value as below

var json = {};

if(updatePropertyInfo.RawDataFromInvoke!=undefined) {

    if(updatePropertyInfo.RawDataFromInvoke.rows!=undefined && updatePropertyInfo.RawDataFromInvoke.rows.length>0) {

        //come from infotable binding

        json = updatePropertyInfo.RawDataFromInvoke.rows[0].MYJSONPROPERTY;

    }

    else {

        //come from direct service output

        json = updatePropertyInfo.RawDataFromInvoke;

    }

}

That's very ugly to to your datashape variable name into the widget code, but.... it works

My Thingworx version is 7.1.4

Regards

Announcements


Top Tags