Why is my jsondata object undefined? - javascript
var jsondata = $.parseJSON('{"bwpaperback":{"creme":{"5x8":[".95",".016"],"5_25x8":[".95",".016"],"5_5x8_5":[".95",".016"],"6x9":[".95",".016"],"pages":["18","1050"]},"white":{"5x8":[".95",".016"],"5_25x8":[".95",".016"],"5_5x8_5":[".95",".016"],"6x9":[".95",".016"],"8x8":[".95",".016"],"8_5x8_5":[".95",".016"],"7x10":["1.35",".021"],"8x10":["1.35",".021"],"8_25x11":["1.35",".021"],"8_5x11":["1.35",".021"],"pages":["18","1200"]}},"bwhardcover":{"case":{"creme":{"5x8":["6.05",".016"],"5_5x8_5":["6.05",".016"],"6x9":["6.05",".016"],"pages":["18","1050"]},"white":{"5x8":["6.05",".016"],"5_5x8_5":["6.05",".016"],"6x9":["6.05",".016"],"8x8":["6.05",".016"],"8_5x8_5":["6.05",".016"],"7x10":["6.05",".021"],"8x10":["6.05",".021"],"8_5x11":["6.05",".021"],"pages":["18","1200"]}},"cloth":{"creme":{"5_5x8_5":["6.05",".016"],"6x9":["6.05",".016"],"pages":["18","1050"]},"white":{"5x8":["6.05",".016"],"5_5x8_5":["6.05",".016"],"6x9":["6.05",".016"],"pages":["18","1200"]}}},"scpaperback":{"5x7":[".95",".026"],"5x8":[".95",".026"],"5_25x8":[".95",".026"],"5_5x8_5":[".95",".026"],"6x9":[".95",".026"],"8_5x8)5":[".95",".026"],"7x10":["1.30",".031"],"8x10":["1.30",".031"],"8_25x11":["1.30",".031"],"8_5x11":["1.30",".031"],"pages":["18","1200"]},"schardcover":{"case":{"5x8":["6.05",".026"],"5_5x8_5":["6.05",".026"],"6x9":["6.05",".026"],"8x8":["6.05",".026"],"8_5x8_5":["6.05",".026"],"7x10":["6.05",".031"],"8x10":["6.05",".031"],"8.5x11":["6.05",".031"],"pages":["18","1200"]},"cloth":{"5x8":["6.05",".026"],"5_5x8_5":["6.05",".026"],"6x9":["6.05",".026"],"pages":["18","1200"]}},"pcpaperback":{"5_5x8_5":["1.05",".06"],"6x9":["1.05",".09"],"8x8":["1.05",".09"],"8_5x8_5":["1.05",".09"],"7x10":["1.55",".10"],"8x10":["1.55",".10"],"8_5x11":["1.55",".10"],"pages":["4,900"]},"pchardcover":{"case":{"5x8":["6.05",".06"],"5_5x8_5":["6.05",".06"],"6x9":["6.05",".091"],"8x8":["6.05",".091"],"8_5x8_5":["6.05",".091"],"7x10":["6.05",".011"],"8x10":["6.05",".011"],"8_5x11":["6.05",".011"],"pages":["24,840"]},"cloth":{"5x8":["6.05",".06"],"5_5x8_5":["6.05",".06"],"6x9":["6.05",".091"],"pages":["24,840"]}}}');
if(main.hasClass('bw') && main.hasClass('paperback')){
baseprice = jsondata[calctype][color][size][0];
perpage = jsondata[calctype][color][size][1];
minpages = jsondata[calctype][color].pages[0];
maxpages = jsondata[calctype][color].pages[1];
}
I'm not sure if I need to provde more code. but it says "Uncaught TypeError: Cannot read property '#' of undefined"
This worked when I was using $.getJSON from an external json file. How can I use this as a object instead of .json?
thanks!
Related
TypeError when Using API in Javascript
I'm trying to make a Trivia Game using Open Trivia DB. What I want is to display only the questions in the triviaQ constant and I did that. The code works, it does what I want it to do BUT, when I refresh the page sometimes, this error shows up in the console: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'question') The error points to: question_data.question and underlines the question which doesn't make sense because it is a valid key from the API json. Plus, what confuses me even more is that it still displays the question even if there is an error and the error appears sometimes. Thank you in advance for your time! Javascript Code: const api_url = 'https://opentdb.com/api.php?amount=10&difficulty=easy&type=boolean' const triviaQ = document.getElementById("triviaQuestion") let question_data = "" async function display() { const response = await fetch(api_url); const data = await response.json() for (let i = 0; i <= 10; i++) { var randNum = Math.floor(Math.random() * 11); question_data = data.results[randNum] triviaQ.innerHTML = question_data.question } } display()
Failed: Cannot read property 'cartblock' of undefined
I'm new to protractor using javascript, I created a simple script that calls data from another js file. I have a file called jsobjectdemo.js that contains <pre> this.productnames = element.all(by.tagName("app-card")); this.cartblock = element(by.css("h4 a")); this.addcartbutton = element(by.css("button[class='btn btn-info']")); </pre> And another file called jscalldemo.js var cart = require('./jsobjectdemo.js'); function addCart(productname){ cart.productnames.each(function(item){ cart.cartblock.getText().then(function(text){ if (text==productname){ cart.addcartbutton.click(); } }) }) } When i ran the script, it returns an error Message: Failed: Cannot read property 'cartblock' of undefined Stack: TypeError: Cannot read property 'cartblock' of undefined at D:\Trainings\Protractor\protractor-workspace\Protractor\jscalldemo.js:8:14
Const loc = { productnames = element.all(by.tagName("app-card")), cartblock = element(by.css("h4 a")), addcartbutton = element(by.css("button[class='btn btn-info']")) } exports.cart = loc; Change your jsobjectdemo.js to the above. And in your jscalldemo.js Const cart = require('./jsobjectdemo.js').cart; Now you can use cart.cartblock in jscalldemo.js
How to use value from Observable inside TypeScript component | Angular 4
I'm trying to get a JSON value I got from an API and set it inside a variable, for example: TS this.graphicService.getDatas().subscribe(datas => { this.datas = datas; console.log(datas); }); test = this.datas[0].subdimensions[0].entry; HTML {{test}} it returns an error on console: ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'subdimensions' of undefined TypeError: Cannot read property 'subdimensions' of undefined at new GraphicsComponent (graphics.component.ts:33)... However, It does work if I use directly on HTML like this: {{datas[0]?.subdimensions[0].entry}} The data is printed correctly then. ..
Try this: let test; this.graphicService.getDatas().subscribe(datas => { this.datas = datas; console.log(datas); test = this.datas[0].subdimensions[0].entry; });
Swagger-ui + oauth -> index.js:24 Uncaught TypeError: Cannot read property 'api' of undefined
first of all i am using a bit modified version of the standard html/js code offered from swagger-ui. Changes are rather simple, instead of using only a single SwaggerUI element like: window.swaggerUi = new SwaggerUi({ .... window.swaggerUi.load(); we iterate over them and create lots of swaggerUI elements: function addSwaggerUI(url, dom_id, host){ window[dom_id] = new SwaggerUi({ .... window[domId].load(); this is our iteration: var services = [{SERVICE_SPECS}]; var doc_container = document.getElementById('service-doc-container'); var index = 0; services.forEach(function(serviceSpec) { var swaggerNode = document.createElement('div'); swaggerNode.id = "swagger-ui-container-" + index; swaggerNode.className = "swagger-ui-wrap"; var messageNode = document.createElement('div'); messageNode.id = "message-bar-" + index; messageNode.className = "swagger-ui-wrap"; doc_container.appendChild(swaggerNode); doc_container.appendChild(messageNode); log("adding service documentation for " + serviceSpec); addServiceDocumentation(serviceSpec, swaggerNode.id, "{SERVICE_HOST}"); index++; }); This worked quiet well until we started using securityDefinitions oAuth: "securityDefinitions": { "OauthSecurity": { "type": "oauth2", "authorizationUrl": "http://localhost/oauth/dialog", "flow": "implicit", "scopes":{ "write:sessions":"kill sessions", "read:sessions":"get sessions" } } Now i get on each swaggerUI this error: index.js:24 Uncaught TypeError: Cannot read property 'api' of undefined Original swaggercode:https://github.com/swagger-api/swagger-ui/tree/master/dist see index.html Can someone help to fix this? (Alternative solution: Anyone know of another way to add multiple web apis from different json files on one html page? ) UPDATE: So i looked at the generated page from swagger.petstore.io and found something called 'authorzie-wrapper'it is possible that this element is missing at my code.
Error Start workflow via JavaScript
I can't get start a Workflow via Web Script. I created the file workflow.get.js: var nodeId = args.nodeid; //fdadc86f-d996-472d-8267-850a63573b02 var workflowName = args.w; //jbpm$wf:adhoc var document = search.findNode("workspace://SpacesStore/" + nodeId); var workflowAction = actions.create("start-workflow"); workflowAction.parameters.workflowName = workflowName; workflowAction.parameters["bpm:workflowDescription"] = "Please edit: " + document.name; workflowAction.parameters["bpm:assignees"] = [people.getPerson("admin"), people.getPerson("admin")]; var futureDate = new Date(); futureDate.setDate(futureDate.getDate() + 7); workflowAction.parameters["bpm:workflowDueDate"] = futureDate; workflowAction.execute(document); workflow.get.desc.xml <webscript> <shortname>Start Workflow</shortname> <description>Testando Start Workflow</description> <url>/workflow?nodeid={idfile}&&w={namewf}</url> <format default="html">argument</format> <authentication>admin</authentication> <transaction>required</transaction> </webscript> and workflow.get.html.ftl The ${args.w} started! when I click http://localhost:8080/alfresco/service/workflow?nodeId=fdadc86f-d996-472d-8267-850a63573b02&w=jbpm$wf:adhoc return the error 06190076 Wrapped Exception (with status template): 06190474 Failed to execute script '/triggerworkflow.get.js (in repository store workspace://SpacesStore/Company Home/Data Dictionary/Web Scripts)': 06190473 Can't find method org.alfresco.repo.jscript.ScriptAction.execute(org.mozilla.javascript.Undefined). (in repository store workspace://SpacesStore/Company Home/Data Dictionary/Web Scripts)#11) Exception: org.alfresco.error.AlfrescoRuntimeException - 08200041 TypeError: Cannot read property "name" from null (workspace://SpacesStore/Company Home/Data Dictionary/Web Scripts Extensions/Workflow/workflow.get.js#7) org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:469) Exception: org.alfresco.scripts.ScriptException - 08200042 Failed to execute script '/Workflow/workflow.get.js (in repository store workspace://SpacesStore/Company Home/Data Dictionary/Web Scripts Extensions)': 08200041 TypeError: Cannot read property "name" from null (workspace://SpacesStore/Company Home/Data Dictionary/Web Scripts Extensions/Workflow/workflow.get.js#7) org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:183) Exception: org.springframework.extensions.webscripts.WebScriptException - 08200035 Wrapped Exception (with status template): 08200042 Failed to execute script '/Workflow/workflow.get.js (in repository store workspace://SpacesStore/Company Home/Data Dictionary/Web Scripts Extensions)' : 08200041 TypeError: Cannot read property "name" from null (workspace://SpacesStore/Company Home/Data Dictionary/Web Scripts Extensions/Workflow/ workflow.get.js#7) org.springframework.extensions.webscripts.AbstractWebScript.createStatusException(AbstractWebScript.java:742) Anybody help me?
Your problem is you're calling arguments one thing in one place, and a different thing in another: var nodeId = args.nodeid; //fdadc86f-d996-472d-8267-850a63573b02 var workflowName = args.w; //jbpm$wf:adhoc vs <url>/workflow?nodeid={idfile}&&w={namewf}</url> You need to get those to agree! I'd suggest, given the URL you seem to already be using from the client, changing your webscript descriptor URL to match what you use, to: <url>/workflow?nodeid={nodeid}&w={w}</url> You should also add logic to check that the node given really exists - search.findNode can return null so you should check that before continuing (eg and give a 404 if not found) Also, you could use utils.getNodeFromString(String) if you'd rather
Please try to start your workflow using this code, replace your code of workflow.get.js with this code and change all the properties according to your requirement. function startWorkflow() { var workflowAction = workflow.getDefinitionByName("activiti$test_wf"); var package= workflow.createPackage(); var wfparams = new Array(); wfparams["model_prefix:req_props_name"] = value2; wfparams["bpm:assignee"] = people.getPerson("ADMIN"); workflowAction.startWorkflow(package, wfparams); } } startWorkflow();