Uibuilder get specific value from json

How to get value from uibuilder json. I try

MSG: {{msgRecvd.payload.item1}}
but it doesn't work
[{"id":"b736e61c.c8cc","type":"tab","label":"Flow 6","disabled":false,"info":""},{"id":"2f27ec13.9dc35c","type":"uibuilder","z":"b736e61c.c8cc","name":"","topic":"","url":"test","fwdInMessages":false,"allowScripts":false,"allowStyles":false,"copyIndex":true,"showfolder":false,"x":370,"y":140,"wires":[[],[]]},{"id":"8673440a.6a7b7","type":"inject","z":"b736e61c.c8cc","name":"","topic":"cardId","payload":"{\"item1\":23,\"item2\":\"test\",\"item3\":45,\"item4\":[\"a1\",\"a2\"]}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":140,"wires":[["2f27ec13.9dc35c","6395d2bc.4ea33c","7bac4b89.24580c"]]},{"id":"f7319816.8d97d8","type":"comment","z":"b736e61c.c8cc","name":"index.js","info":"/* jshint browser: true, esversion: 5, asi: true */\n/*globals Vue, uibuilder */\n// @ts-nocheck\n/*\n  Copyright (c) 2019 Julian Knight (Totally Information)\n\n  Licensed under the Apache License, Version 2.0 (the \"License\");\n  you may not use this file except in compliance with the License.\n  You may obtain a copy of the License at\n\n  http://www.apache.org/licenses/LICENSE-2.0\n\n  Unless required by applicable law or agreed to in writing, software\n  distributed under the License is distributed on an \"AS IS\" BASIS,\n  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n  See the License for the specific language governing permissions and\n  limitations under the License.\n*/\n'use strict'\n\n/** @see https://github.com/TotallyInformation/node-red-contrib-uibuilder/wiki/Front-End-Library---available-properties-and-methods */\n\n// eslint-disable-next-line no-unused-vars\nvar app1 = new Vue({\n    el: '#app',\n    data: {\n        startMsg    : 'Vue has started, waiting for messages',\n        feVersion   : '',\n        counterBtn  : 0,\n        inputText   : null,\n        inputChkBox : false,\n        socketConnectedState : false,\n        serverTimeOffset     : '[unknown]',\n        imgProps             : { width: 75, height: 75 },\n\n        msgRecvd    : '[Nothing]',\n        msgsReceived: 0,\n        msgCtrl     : '[Nothing]',\n        msgsControl : 0,\n\n        msgSent     : '[Nothing]',\n        msgsSent    : 0,\n        msgCtrlSent : '[Nothing]',\n        msgsCtrlSent: 0,\n    }, // --- End of data --- //\n    computed: {\n        hLastRcvd: function() {\n            var msgRecvd = this.msgRecvd\n            if (typeof msgRecvd === 'string') return 'Last Message Received = ' + msgRecvd\n            else return 'Last Message Received = ' + this.syntaxHighlight(msgRecvd)\n        },\n        hLastSent: function() {\n            var msgSent = this.msgSent\n            if (typeof msgSent === 'string') return 'Last Message Sent = ' + msgSent\n            else return 'Last Message Sent = ' + this.syntaxHighlight(msgSent)\n        },\n        hLastCtrlRcvd: function() {\n            var msgCtrl = this.msgCtrl\n            if (typeof msgCtrl === 'string') return 'Last Control Message Received = ' + msgCtrl\n            else return 'Last Control Message Received = ' + this.syntaxHighlight(msgCtrl)\n        },\n        hLastCtrlSent: function() {\n            var msgCtrlSent = this.msgCtrlSent\n            if (typeof msgCtrlSent === 'string') return 'Last Control Message Sent = ' + msgCtrlSent\n            //else return 'Last Message Sent = ' + this.callMethod('syntaxHighlight', [msgCtrlSent])\n            else return 'Last Control Message Sent = ' + this.syntaxHighlight(msgCtrlSent)\n        },\n    }, // --- End of computed --- //\n    methods: {\n        increment: function(event) {\n            console.log('Button Pressed. Event DatA: ', event)\n\n            // Increment the count by one\n            this.counterBtn = this.counterBtn + 1\n            var topic = this.msgRecvd.topic || 'uibuilder/vue'\n            uibuilder.send( {\n                'topic': topic,\n                'payload': {\n                    'type': 'counterBtn',\n                    'btnCount': this.counterBtn,\n                    'message': this.inputText,\n                    'inputChkBox': this.inputChkBox\n                }\n            } )\n\n        }, // --- End of increment --- //\n\n        // return formatted HTML version of JSON object\n        syntaxHighlight: function(json) {\n            json = JSON.stringify(json, undefined, 4)\n            json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')\n            json = json.replace(/(\"(\\\\u[a-zA-Z0-9]{4}|\\\\[^u]|[^\\\\\"])*\"(\\s*:)?|\\b(true|false|null)\\b|-?\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d+)?)/g, function (match) {\n                var cls = 'number'\n                if (/^\"/.test(match)) {\n                    if (/:$/.test(match)) {\n                        cls = 'key'\n                    } else {\n                        cls = 'string'\n                    }\n                } else if (/true|false/.test(match)) {\n                    cls = 'boolean'\n                } else if (/null/.test(match)) {\n                    cls = 'null'\n                }\n                return '<span class=\"' + cls + '\">' + match + '</span>'\n            })\n            return json\n        }, // --- End of syntaxHighlight --- //\n    }, // --- End of methods --- //\n\n    // Available hooks: init,mounted,updated,destroyed\n    mounted: function(){\n        //console.debug('[indexjs:Vue.mounted] app mounted - setting up uibuilder watchers')\n\n        /** **REQUIRED** Start uibuilder comms with Node-RED @since v2.0.0-dev3\n         * Pass the namespace and ioPath variables if hosting page is not in the instance root folder\n         * The namespace is the \"url\" you put in uibuilder's configuration in the Editor.\n         * e.g. If you get continual `uibuilderfe:ioSetup: SOCKET CONNECT ERROR` error messages.\n         * e.g. uibuilder.start('uib', '/nr/uibuilder/vendor/socket.io') // change to use your paths/names\n         */\n        uibuilder.start()\n\n        var vueApp = this\n\n        // Example of retrieving data from uibuilder\n        vueApp.feVersion = uibuilder.get('version')\n\n        /** You can use the following to help trace how messages flow back and forth.\n         * You can then amend this processing to suite your requirements.\n         */\n\n        //#region ---- Trace Received Messages ---- //\n        // If msg changes - msg is updated when a standard msg is received from Node-RED over Socket.IO\n        // newVal relates to the attribute being listened to.\n        uibuilder.onChange('msg', function(newVal){\n            //console.info('[indexjs:uibuilder.onChange] msg received from Node-RED server:', newVal)\n            vueApp.msgRecvd = newVal\n              if ( newVal.topic == 'cardId' ) {\n        vueApp.cardId = newVal.payload\n        }\n        })\n        // As we receive new messages, we get an updated count as well\n        uibuilder.onChange('msgsReceived', function(newVal){\n            //console.info('[indexjs:uibuilder.onChange] Updated count of received msgs:', newVal)\n            vueApp.msgsReceived = newVal\n        })\n\n        // If we receive a control message from Node-RED, we can get the new data here - we pass it to a Vue variable\n        uibuilder.onChange('ctrlMsg', function(newVal){\n            //console.info('[indexjs:uibuilder.onChange:ctrlMsg] CONTROL msg received from Node-RED server:', newVal)\n            vueApp.msgCtrl = newVal\n        })\n        // Updated count of control messages received\n        uibuilder.onChange('msgsCtrl', function(newVal){\n            //console.info('[indexjs:uibuilder.onChange:msgsCtrl] Updated count of received CONTROL msgs:', newVal)\n            vueApp.msgsControl = newVal\n        })\n        //#endregion ---- End of Trace Received Messages ---- //\n\n        //#region ---- Trace Sent Messages ---- //\n        // You probably only need these to help you understand the order of processing //\n        // If a message is sent back to Node-RED, we can grab a copy here if we want to\n        uibuilder.onChange('sentMsg', function(newVal){\n            //console.info('[indexjs:uibuilder.onChange:sentMsg] msg sent to Node-RED server:', newVal)\n            vueApp.msgSent = newVal\n        })\n        // Updated count of sent messages\n        uibuilder.onChange('msgsSent', function(newVal){\n            //console.info('[indexjs:uibuilder.onChange:msgsSent] Updated count of msgs sent:', newVal)\n            vueApp.msgsSent = newVal\n        })\n\n        // If we send a control message to Node-RED, we can get a copy of it here\n        uibuilder.onChange('sentCtrlMsg', function(newVal){\n            //console.info('[indexjs:uibuilder.onChange:sentCtrlMsg] Control message sent to Node-RED server:', newVal)\n            vueApp.msgCtrlSent = newVal\n        })\n        // And we can get an updated count\n        uibuilder.onChange('msgsSentCtrl', function(newVal){\n            //console.info('[indexjs:uibuilder.onChange:msgsSentCtrl] Updated count of CONTROL msgs sent:', newVal)\n            vueApp.msgsCtrlSent = newVal\n        })\n        //#endregion ---- End of Trace Sent Messages ---- //\n\n        // If Socket.IO connects/disconnects, we get true/false here\n        uibuilder.onChange('ioConnected', function(newVal){\n            //console.info('[indexjs:uibuilder.onChange:ioConnected] Socket.IO Connection Status Changed to:', newVal)\n            vueApp.socketConnectedState = newVal\n        })\n        // If Server Time Offset changes\n        uibuilder.onChange('serverTimeOffset', function(newVal){\n            //console.info('[indexjs:uibuilder.onChange:serverTimeOffset] Offset of time between the browser and the server has changed to:', newVal)\n            vueApp.serverTimeOffset = newVal\n        })\n\n    } // --- End of mounted hook --- //\n\n}) // --- End of app1 --- //\n\n// EOF","x":230,"y":100,"wires":[]},{"id":"687f6af.8329214","type":"comment","z":"b736e61c.c8cc","name":"index.html","info":"<!doctype html>\n<!-- Note that adding an appcache really speeds things up after the first load\n    You need to amend the appcache file to meet your needs.\n    Don't forget to change the appcache file if you update ANY\n    of the files in it otherwise the old versions will ALWAYS be used.\n<html lang=\"en\" manifest=\"./uibuilder.appcache\">\n-->\n<html lang=\"en\">\n<!--\n    This is the default, template html for uibuilder.\n    It is meant to demonstrate the use of VueJS & bootstrap-vue to dynamically\n    update the ui based on incoming/outgoing messages from/to the\n    Node-RED server.\n\n    You will want to alter this to suite your own needs. To do so,\n    copy this file to <userDir>/uibuilder/<url>/src.\n-->\n<head>\n    <meta charset=\"utf-8\">\n    <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n    <meta name=\"viewport\" content=\"width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes\">\n\n    <title>Node-RED UI Builder</title>\n    <meta name=\"description\" content=\"Node-RED UI Builder - VueJS + bootstrap-vue version\">\n\n    <link rel=\"icon\" href=\"./images/node-blue.ico\">\n\n    <!-- See https://goo.gl/OOhYW5 -->\n    <link rel=\"manifest\" href=\"./manifest.json\">\n    <meta name=\"theme-color\" content=\"#3f51b5\">\n\n    <!-- Used if adding to homescreen for Chrome on Android. Fallback for manifest.json -->\n    <meta name=\"mobile-web-app-capable\" content=\"yes\">\n    <meta name=\"application-name\" content=\"Node-RED UI Builder\">\n\n    <!-- Used if adding to homescreen for Safari on iOS -->\n    <meta name=\"apple-mobile-web-app-capable\" content=\"yes\">\n    <meta name=\"apple-mobile-web-app-status-bar-style\" content=\"black-translucent\">\n    <meta name=\"apple-mobile-web-app-title\" content=\"Node-RED UI Builder\">\n\n    <!-- Homescreen icons for Apple mobile use if required\n        <link rel=\"apple-touch-icon\" href=\"./images/manifest/icon-48x48.png\">\n        <link rel=\"apple-touch-icon\" sizes=\"72x72\" href=\"./images/manifest/icon-72x72.png\">\n        <link rel=\"apple-touch-icon\" sizes=\"96x96\" href=\"./images/manifest/icon-96x96.png\">\n        <link rel=\"apple-touch-icon\" sizes=\"144x144\" href=\"./images/manifest/icon-144x144.png\">\n        <link rel=\"apple-touch-icon\" sizes=\"192x192\" href=\"./images/manifest/icon-192x192.png\">\n    -->\n\n    <link type=\"text/css\" rel=\"stylesheet\" href=\"../uibuilder/vendor/bootstrap/dist/css/bootstrap.min.css\" />\n    <link type=\"text/css\" rel=\"stylesheet\" href=\"../uibuilder/vendor/bootstrap-vue/dist/bootstrap-vue.css\" />\n    \n    <link type=\"text/css\" rel=\"stylesheet\" href=\"./index.css\" media=\"all\">\n</head>\n<body>\n    \n    <div class=\"classic-form-page\">\n    <div id=\"app\" v-cloak>\n        \n        \n\n         \n        <b-container id=\"app_container\">\n<div>{{msgsReceived}}</div>\n<p>\n<div>Current Card No: {{cardId}}</div>\n</p>\n<div>\n    Sensor value: {{msgRecvd.payload}}\n</div>\n<div>MSG: {{msgRecvd.payload}}</div>\n\n\n\n\n      \n\n        </b-container>\n    </div>\n\n    <!-- These MUST be in the right order. Note no leading / -->\n    <!-- REQUIRED: Socket.IO is loaded only once for all instances\n                     Without this, you don't get a websocket connection -->\n    <script src=\"../uibuilder/vendor/socket.io/socket.io.js\"></script>\n\n    <!-- --- Vendor Libraries - Load in the right order --- -->\n    <script src=\"../uibuilder/vendor/vue/dist/vue.js\"></script> <!-- dev version with component compiler -->\n    <!-- <script src=\"../uibuilder/vendor/vue/dist/vue.min.js\"></script>   prod version with component compiler -->\n    <!-- <script src=\"../uibuilder/vendor/vue/dist/vue.runtime.min.js\"></script>   prod version without component compiler -->\n    <script src=\"../uibuilder/vendor/bootstrap-vue/dist/bootstrap-vue.js\"></script>\n\n    <!-- REQUIRED: Sets up Socket listeners and the msg object -->\n    <!-- <script src=\"./uibuilderfe.js\"></script>   //dev version -->\n    <script src=\"./uibuilderfe.min.js\"></script> <!--    //prod version -->\n    <!-- OPTIONAL: You probably want this. Put your custom code here -->\n    <script src=\"./index.js\"></script>\n</div>\n</body>\n\n</html>","x":360,"y":100,"wires":[]},{"id":"6395d2bc.4ea33c","type":"debug","z":"b736e61c.c8cc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.item1","targetType":"msg","x":390,"y":200,"wires":[]},{"id":"7bac4b89.24580c","type":"debug","z":"b736e61c.c8cc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":370,"y":240,"wires":[]}]

Wait, no - You are using msgRecvd - is that what is in the onChange function in your index.js file?

If so, you need to set a pre-defined VueJS variable that exists in the data section. So in the data section you have vueVar: '', in the onchange function you have something like vueVar = msgRecvd.payload.item1 and in your html you have {{vueVar}}


Most likely the format of your payload isn't what you think.

Add a debug node to output a copy of the msgs you are sending and use the small icons to copy the data and paste it here if you can.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.