Thanks for the tree-model-js, great lib!
I am new to Node.js and I'm trying to import the tree-model. All NPMed successfully.
I am trying to make Node.js work with your library. I guess it is as much a Node question and not so much tree-model issue, but asking anyway just in case the lib needs to be changed for it.
I have the following:
var tm = require('tree-model');
//all good so far.
but when I am trying to recreate the code that works on my webpage
//is this how I access it?
tm.tree = new TreeModel();
it is giving me an error. Do you have any examples on how this can be achieved in Node?
Essentially I am trying to do this within my main.js Node file but struggling to understand how to access the variables/functions. It all works well when on a webpage when I do the following:
tree = new TreeModel();
root = tree.parse({ name: "Ben and Jerry" });
Any examples much appreciated. Please keep in mind that I am new to Node.js and somehow rookie on javascript. I learn better from examples so feel free to point me in the right direction.
The error is quite simple: TreeModel is not defined.
require('tree-model') returns new Node(this.config, model) and in your code, the Node is assigned to variable tm.
You should use new tm() to instantiate Node or change the variable name to TreeModel
Related
Good afternoon fellow developers,
I am currently trying to develop a function that instantiates business objects dynamically based on the value of the string it receives as a parameter. I know this can be done in JavaScript as I have done it before and, just to be sure, I even tested it again in Visual Studio Code after having encountered this issue in my SAPUI5 app. My function's code looks somewhat like this:
createObject: function (sObject) {
var newObject = new this[sObject]();
// var newObject = new [sObject](); I also tried this way.
};
For the sake of testing this function, the sObject string currently contains the hardcoded value "Order" and I am importing my Order.js object into the file where i'm trying to instantiate this objects dynamically. No matter what I try I keep getting this error when debugging my code:
TypeError: this[sObject] is not a constructor
I was wondering if some of you might have tried something similar before and might be able to point me in the right direction. Even if there are ways for me to work around this issue, it would be really nice if I learnt how to do this dynamically since I was planning on using this approach on several different scenarios. I look forward to reading from you!
It is a really unsafe practice to instantiate objects from a string and an ATROCIOUS one to do it from a parameter a user can supply. If you have a limited set of objects its much safer to have a big switch statement.
switch(name) {
"objA": return new ObjA();
}
Hoping someone can shed some light on using Cognito with plain JavaScript. No npm, no webpack, just plain JavaScript. I found a post that had a great example including the required AWS JavaScript libraries. I worked from this example until I ran into the problem of sign out not working. I thought perhaps the libraries in the example were out of date so I went looking for the latest. This is where things got confusing. In the example I had the following JavaScript libraries - amazon-cognito-identity.min.js, aws-cognito-sdk.min.js, and aws-sdk.min.js. I assume that aws-cognito-sdk must no longer exist? I updated the other two and see that there is an amazon-cognito-auth library. Do I need that? Anyhow with those three libraries the existing code no longer functions. I end up with errors like "AWSCognito is undefined" etc.
Hoping someone can point me in the right direction and show me where the downloads, documentation, etc for using Cognito in plain JavaScript are
Find hereunder a template I created for myself to work from. It is in "plain javascript" and in an angularjs app.
My template: https://github.com/PouncingPoodle/aws-cognito-angularjs/tree/master
based on: https://github.com/takanorig/aws-cognito-angularjs
Always make sure that you use the correct versions of scripts and the correlating apiVersion when you call a Lambda function for example
There might be bad practice involved but as far as I could research it should be all fine.
You can perform the logout using below code snippet. I haven't faced such strange errors while using this function.
var poolData = {
UserPoolId: '...', // Your user pool id here
ClientId: '...', // Your client id here
};
var userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);
var userData = {
Username: 'username',
Pool: userPool,
};
var cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
cognitoUser.signOut();
if you want to make the user logout from all the devices that he has got logged in from, then you can replace the last line of previous code with below code line.
cognitoUser.globalSignOut(callback);
You can refer below article to get a better understanding about the usage of amazon-cognito-identity-js package.
https://medium.com/#sankharathnayaka/aws-cognito-authentication-without-using-amplify-8d0e3af997c2
I've been serching the net for quite some time and maybe there is no solution for my problem but I hoped you might be able to help me. I'm currently trying to establish a connection to CatiaV5 via JavaScript. The connection itsself is working just fine. Basically it looks like this now:
var catia = new ActiveXObject('CATIA.Application');
var doc = catia.ActiveDocument;
But here's my problem. The returned object is a Collection in VB and there seems to be no DataType equivalent to this. So this is what i get when i try to read my variables. For example:
doc.Product
returns
[object] {};
So this seems to be empty. However if then I try to get
doc.Product.Name
which by that logic should be undefined, instead i get
"Part1"
so the correct name of my Part/Product is returned.
All the Catia stuff probably isn't that relevant for the question.
my question: Is there any way to somehow parse a VB-Collection on a JavaScript object or something similar, to get the contents of what is returned?
OK,
here's the thing. I found out, that you can't really browse throug ActiveXObjects directly in the console in general. In the IE-Dev-Tools i was however able to use the Locals-Watch to browse through the Object. I didn't find a nice way to Parse it onto a JSON-Object, however the manual way to create a new Object and add the Keys piece by piece works.
I'm migrating an install script from js to vb.net and I'm facing the following problem.
I'm having issues as JS is late-binded so I need to research the datatype returned by each method in order to make the strong typed counterpart in vb.net (or C# for the matter)
In the original js install script, I'm getting to a point where I don't know how to port this 2 calls:
var objWMIService = GetObject("winmgmts:\\\\.\\root\\cimv2");
var objAccount = objWMIService.Get("Win32_SID.SID='S-1-1-0'");
If I leave data type inference, I get COMType, so I can't call the Get method from the generated object.
I think I could solve this by using IDispatch, but It's been like 10 years since I used IDispatch and I can't rememeber exactly how to do it.
Also, after further research, I've seen that the internal COM is actually a SWBemServicesEX object, which I don't know what to reference in order to generate a COM interop system.
I would appreciate it a lot, if anyone can provide any ideas or solutions to this issue.
Current vb.NET code is just:
Dim objWMIService = GetObject("winmgmts:\\.\root\cimv2")
not sure how to be able to call the Get method from objWMIService, and how to determine what this method actually returns!
I ended doing what Steve says in his answer and it solved the issue for me. I'm not very happy with runtime late binding, but it gets the job done!
for reference:
Try using Dim objWMIService as Object = GetObject("winmgmts:\.\root\cimv2") instead. Then you can use Dim objAccount as Object = objWMIService.Get("Win32_SID.SID='S-1-1-0'"). When doing late-binding, declare everything as an object. You can then step through the code in debug and sometimes see what the return is. Then search for the methods/properties/etc for that type and write your next line. Takes a little work but you don't need references to any dlls. Theres just an assumption that the dll are registered (COM) or in your path that .Net follows (CLR)
This seems like it would be a very easy problem to solve, but I've been banging my head against it for almost an hour. All I need is a snippet of javascript/extendscript code so that my InDesign CS6 script can create a folder. I know the existing folder in which the new one should be created, and I know the name that this new folder should be called. But how do I get javascript to do it?
By the way, all searches online for the folderObj.create() method, which is in the JavaScript Tools Guide, prove useless. I've tried several variations on that method, but nothing seems to actually create the folder. What am I missing?
var f = new Folder('/c/myfolder/');
if (!f.exists)
f.create();
Okay, found a work-around: I have to specify the folder absolutely, rather than use the ~ home shortcut. In addition, I have use /Volumes at the very beginning. Thus, the code becomes:
var f = new Folder("/Volumes/apache HD/Users/apache/Desktop/my_new_fodler");
f.create();
And that seems to work, finally. Thanks for your help, #Anna Forrest and #fabiantheblind! (You seem to be the resident ExtendScript expert around here.)
try this:
var f = new Folder("~/Desktop/my_new_fodler");
f.create();