Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X
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???
}
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