Loading binary file on VUEJS with jBinary - javascript

I'm trying to load a binary file et read the content
For this, i'm using the load function to get my binary file and then,
I call a function that parse the binary file.
The problem is , I can access the datas
I keep havin this error :
Uncaught (in promise) TypeError: Cannot read property 'parsePeturboDATFiles' of undefined
at eval (eval at 79 (0.05b4762….hot-update.js:7), :128:11)
I did try to console.log my data to see what is going wrong, but I can print my data but I can't pass it to my other parsing functions ... I cannot figure why.
Here's my code by the way :
<template>
<div class="cde">
<h1></h1>
</div>
</template>
<script>
import jbinary from 'jbinary'
export default {
name: 'CDE',
data () {
return {
}
},
methods : {
parsePeturboDATFiles : function (data) {
console.log(data)
},
},
mounted : function () {
jbinary.load('./static/test.dat').then(function (data) {
console.log(data.view) //works fine
this.parsePeturboDATFiles(data.view) //get an error
})
}
}
</script>

The error is saying that it's not able to read the parsePeturboDATFiles property because the this variable is evaluating to undefined. Store a reference to this in another variable self and then use that to call parsePeturboDATFiles():
mounted : function () {
var self = this;
jbinary.load('./static/test.dat').then(function (data) {
self.parsePeturboDATFiles(data.view);
})
}

Related

Cannnot Load Workbook in SuiteScript 2.0 N/query Module

I'm trying to use the query module in NetSuite's SuiteScript 2.0 API set, learn how it works so we can try to use it to display data too complex for regular scripted/saved searches. I started off by taking a default template and saving it. In the UI it comes up with results without any issues. I've tried testing with the following code:
require(['N/query']);
var query = require('N/query');
var wrkBk = query.load({ id : "custworkbook1" });
However, all I get is the following error:
Uncaught TypeError: Cannot read property '1' of undefined
at loadCondition (N.js?NS_VER=2021.1.0&minver=60&SS_JS_VERSION=1:17469)
at loadCondition (N.js?NS_VER=2021.1.0&minver=60&SS_JS_VERSION=1:17443)
at loadPostProcess (N.js?NS_VER=2021.1.0&minver=60&SS_JS_VERSION=1:17387)
at Object.loadQuery [as load] (N.js?NS_VER=2021.1.0&minver=60&SS_JS_VERSION=1:17299)
at <anonymous>:1:19
Just for kicks, I thought I'd try the asynchronous version, as well, with the following:
require(['N/query']);
var query = require('N/query');
var wrkBk = null;
query.load.promise({
id : "custworkbook1"
}).then(function(result) {
wrkBk = result;
}).catch(function(err) {
console.log("QUERY LOAD PROMISE ERROR\n\n", err);
})
And like before, got a similar error:
QUERY LOAD PROMISE ERROR
TypeError: Cannot read property '1' of undefined
at loadCondition (N.js?NS_VER=2021.1.0&minver=60&SS_JS_VERSION=1:17469)
at loadCondition (N.js?NS_VER=2021.1.0&minver=60&SS_JS_VERSION=1:17443)
at loadPostProcess (N.js?NS_VER=2021.1.0&minver=60&SS_JS_VERSION=1:17387)
at callback (N.js?NS_VER=2021.1.0&minver=60&SS_JS_VERSION=1:17410)
at myCallback (N.js?NS_VER=2021.1.0&minver=60&SS_JS_VERSION=1:2242)
at XMLHttpRequest.C.f.onload (bootstrap.js:477)
If I run the following code, I get results without errors:
query.listTables({ workbookId : "custworkbook1" });
[
{
"name": "Sales (Invoiced)",
"scriptId": "custview2_16188707990428296095"
}
]
Any idea as to what I'm missing?
I think you're loading the module incorrectly, missing the callback. As per the Help Center, it should be something like:
require(['N/query'], function (query)
{
var wrkBk = query.load({ id : "custworkbook1" });
...do stuff with wrkBk
})
Or for SS2.1:
require(['N/query'], (query) => {
let wrkBk = query.load({ id : "custworkbook1" });
...do stuff with wrkBk
})

error in calling data to view in laravel and vue js

i am trying to show some table data in view using vue js and laravel :
here is what i have tried :
this is comment controller :
public function index()
{
$comment = Comment::Latest()->paginate(10);
return new CommentResource($comment);
}
here is my vue js comment script
export default {
data: function() {
return {
comments: {}
}
},
created() {
this.loadComments();
}
,
methods: {
loadComments(){
axios.get("../api/comment").then(
({ data })=>(this.comments - data.data)
// response => this.comments = response.data
);
},
}
}
and finally the html part of vue html
<div v-for="comment in comments" >
{{ comment.title }}
</div>
the result is this error i get in browser :
[Vue warn]: Error in render: "TypeError: Cannot read property 'title' of undefined"
and here
[Vue warn]: Property or method "comment" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://v2.vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.
and
TypeError: Cannot read property 'title' of undefined
btw i am sure that i have this because this is my api that i recice on
http://localhost:8000/api/comment
{"current_page":1,"data":[{"id":1,"title":"asd","body":"asd","user_id":1,"user_email":"asd","status":1,"created_at":null,"updated_at":null}],"first_page_url":"http:\/\/localhost:8000\/api\/comment?page=1","from":1,"last_page":1,"last_page_url":"http:\/\/localhost:8000\/api\/comment?page=1","next_page_url":null,"path":"http:\/\/localhost:8000\/api\/comment","per_page":10,"prev_page_url":null,"to":1,"total":1}
and when i console log this :
axios.get("../api/comment").then(({ data }) => (console.log(data)))
i get this result :
You're already extracting data from the response. So either you use the response object like this :
axios.get("../api/comment").then((response) => (this.comments = response.data.data)));
Or you extract the data property and use it.
axios.get("../api/comment").then(({ data }) => (this.comments = data.data)));
This is because axios returns a response object that has a data property that contains the server response. As your server response also has a data property that you want to use, you want to use response.data.data

node.js Error generating response. TypeError: response.json is not a function

In my node app, I'm trying to return a simple object and getting this error in my console:
Error generating response. TypeError: response.json is not a function
code in my messaging.js file :
module.exports = {
getConfig: function(res) {
getConfig(res);
}
};
function getConfig(response) {
response.json({
enabledForAll: false,
limit: 100
});
};
In main.js
const messaging = require("./modules/messaging.js");
Parse.Cloud.define("getConfig", messaging.getConfig);
Any advice? Thanks
A parse FunctionResponse only has two properties. success and error.
Additionally, the data portion of the define callback has two function inputs, FunctionRequest and FunctionResponse, so you may need something like function(req,res){ res.success();}

Using Axios and Vue to fetch api data - returning undefined

Running into a snag with trying to integrate my API with Vue/Axios. Basically, Axios is getting the data (it DOES console.log what I want)... But when I try to get that data to my empty variable (in the data object of my component) to store it, it throws an "undefined at eval" error. Any ideas on why this isn't working for me? Thanks!
<template>
<div class="wallet-container">
<h1 class="title">{{ title }}</h1>
<div class="row">
{{ thoughtWallet }}
</div>
</div>
</template>
<script>
import axios from 'axios';
export default {
name: 'ThoughtWallet',
data () {
return {
title: 'My ThoughtWallet',
thoughtWallet: [],
}
},
created: function() {
this.loadThoughtWallet();
},
methods: {
loadThoughtWallet: function() {
this.thoughtWallet[0] = 'Loading...',
axios.get('http://localhost:3000/api/thoughts').then(function(response) {
console.log(response.data); // DISPLAYS THE DATA I WANT
this.thoughtWallet = response.data; // THROWS TYPE ERROR: Cannot set property 'thoughtWallet' of undefined at eval
}).catch(function(error) {
console.log(error);
});
}
}
}
</script>
Because you're using .then(function(..) { }) this won't refer to the vue context this.
You have two solutions, one is to set a variable that references the this you want before the axios call, e.g.:
var that = this.thoughtWallet
axios.get('http://localhost:3000/api/thoughts').then(function(response) {
console.log(response.data); // DISPLAYS THE DATA I WANT
that = response.data; // THROWS TYPE ERROR: Cannot set property 'thoughtWallet' of undefined at eval
}).catch(function(error) {
console.log(error);
});
The other is to use the new syntax (for which you need to make sure your code is transpiled correctly for browsers that don't support it yet), which allows you to access this inside the scoped body of the axios then.
axios.get('http://localhost:3000/api/thoughts').then((response) => {
console.log(response.data); // DISPLAYS THE DATA I WANT
this.thoughtWallet = response.data; // THROWS TYPE ERROR: Cannot set property 'thoughtWallet' of undefined at eval
}).catch(function(error) {
console.log(error);
});
The reason this happens is because inside that function/then, this will be referring to the context of the function, hence there won't be a thoughtWallet property
this.thoughtWallet inside the .get method is referring to the axios object, not Vue's. You can simply define Vue's this on the start:
methods: {
loadThoughtWallet: function() {
let self = this;
this.thoughtWallet[0] = 'Loading...',
axios.get('http://localhost:3000/api/thoughts').then(function(response) {
console.log(response.data); // DISPLAYS THE DATA I WANT
self.thoughtWallet = response.data;
}).catch(function(error) {
console.log(error);
});
}
}

Polymer dom-repeat issue

While rendering with Polymer an array of objects, it keeps launching me an exception.
Here's the data model retrieved from server:
{
"lastUpdate":"yyyy-MM-ddTHH:mm:ss.mmm",
"info": [
{
"title": "Some nice title"
},
...
]
}
Here's my Polymer component template:
<dom-module is="items-list">
<template>
<dl>
<dt>last update:</dt>
<dd>[[$response.lastUpdate]]</dd>
<dt>total items:</dt>
<dd>[[$response.info.length]]</dd>
</dl>
<template is="dom-repeat" items="{{$response.info}}">
{{index}}: {{item.title}}
</template>
</template>
<script src="controller.js"></script>
</dom-module>
And here's the controller:
'use strict';
Polymer(
{
properties: {
info: {
type: Array
},
$response: {
type: Object,
observer: '_gotResponse'
}
},
_gotResponse: function(response)
{
console.log(response);
if (response.info.length)
{
try
{
//here I try to set info value
}
catch(e)
{
console.error(e);
}
}
},
ready: function()
{
//set some default value for info
},
attached: function()
{
//here I request the service for the info
}
}
);
If tried to set info value as:
this.info = response.info;
this.set('info', response.info);
this.push('info', response.info[i]); //inside a loop
But the result breaks after rendering the first item, the exception launched is:
"Uncaught TypeError: Cannot read property 'value' of null"
If info === $response.info then why not just use items={{info}} in the repeat?
edit:
Try to modify your code in the following way.
'use strict';
Polymer({
properties: {
$response: {
type: Object
}
},
_gotResponse: function(response)
{
console.log(response);
...
this.$response = response
...
},
attached: function()
{
//here I request the service for the info
someAjaxFn(someParam, res => this._gotResponse(res));
}
});
You don't need an observer in this case. You only use an explicit observer when the implicit ones don't/won't work. I.e. fullName:{type:String, observer:_getFirstLastName}
or
value:{type:String, observer:_storeOldVar}
...
_storeOldVar(newValue, oldValue) {
this.oldValue = oldValue;
}
if you are updating the entire array, ie this.info, then you simple use this.info = whatever once within your function. If you don't want to update the entire array, just some element within it, then you will want to use polymer's native array mutation methods as JS array method doesn't trigger the observer.
Again, since your template doesn't use info, then you don't need the property info. If you want to keep info, then don't store info within $response. In fact, $ has special meaning in polymer so try not to name properties with it. you can simply use the property info and lastUpdate for your polymer.
Last note, beware of variable scoping when you invoke functions from polymer. Since functions within polymer instances often use this to refer to itself, it may cause
Uncaught TypeError: Cannot read property 'value' ..."
as this no longer refers to the polymer instance at the time of resolve.
For example, suppose your host html is
...
<items-list id='iList'></items-list>
<script>
iList._gotResponse(json); // this will work.
setTimeout(() => iList.gotResponse(json),0); //this will also work.
function wrap (fn) {fn(json)}
wrap (iList._gotResponse); //TypeError: Cannot read property '$response' of undefined.
function wrap2(that, fn) {fn.bind(that)(json)}
wrap2 (iList,iList._gotResponse); // OK!
wrap (p=>iList._gotResponse(p)) //OK too!!
wrap (function (p) {iList._gotResponse(p)}) //OK, I think you got the idea.
</script>

Categories

Resources