angular dynamic (json chain) variables in ctrl variable definitions - json

Do you know how to use dynamic/chained variables inside a controller variable definition?
I have created this plnkr to further outline what I am trying to achieve: http://plnkr.co/edit/xOjhf8b7ZIxVhc1Id3xo
In the NodeCtrl, I am trying to dynamically access a node from a json object and I can't find the correct syntax to write out the chain.
I have tried a number of combinations but haven't found the correct way yet:
//var jsonChunk = "data." + $scope.transcendType;
$scope.tabinventory = data.$scope.transcendType;
//data;
//jsonChunk;
//function() { return "data." + $scope.transcendType; };
alert($tabinventory[0].title)
//alert($scope.tabinventory.project[0].title);
Any help you could provide would be greatly appreciated.
All the best,
Ben

Have you tried logging $scope.transcendType to make sure it's properly defined in that context?
Assuming it's properly defined, try data[$scope.transcendType].

Related

interpreting a json string

I have an object in my database following a file upload that look like this
a:1:{s:4:"file";a:3:{s:7:"success";b:1;s:8:"file_url";a:2:{i:0;s:75:"http://landlordsplaces.com/wp-content/uploads/2021/01/23192643-threepersons.jpg";i:1;s:103:"http://landlordsplaces.com/wp-content/uploads/2021/01/364223-two-female-stick-figures.jpg";}s:9:"file_path";a:2:{i:0;s:93:"/var/www/vhosts/landlordsplaces.com/httpdocs/wp-content/uploads/2021/01/23192643-threepersons.jpg";i:1;s:121:"/var/www/vhosts/landlordsangel.com/httpdocs/wp-content/uploads/2021/01/364223-two-female-stick-figures.jpg";}}}
I am trying with no success to parse extract the two jpg urls programmatically from the object so i can show the images ont he site. Tried assigning parse(object) but that isnt helping. I just need to get the urls out.
Thank you in anticipation of any general direction
What you're looking at is not a JSON string. It is a serialized PHP object. If this database entry was created by Forminator, you should use the Forminator API to retrieve the needed form entry. The aforementioned link points to the get_entry method, which I suspect is what you're looking for (I have never used Forminator), but in any case, you should look for a method that will return that database entry as a PHP object containing your needed URLs.
In case it is ever of any help to anyone the answer to the question was based on John input. The API has the classes to handle that without needing to understand the data structure.
Forminator_API::initialize();
$form_id = 1449; // ID of a form
$entry_id = 3; // ID of an entry
$entry = Forminator_API::get_entry( $form_id, $entry_id );
$file_url = $entry->meta_data['upload-1']['value']['file']['file_url'];
$file_path = $entry->meta_data['upload-1']['value']['file']['file_path'];
var_dump($entry); //contains paths and urls
Hope someone benefits.

Grabbing associationType in Sequelize

I was reading the Sequelize documentation and I am trying to figure out how to get the associationType of a model. It seems like you should be able to import a model (e.g. Posts) and call Posts.associationType or Posts.association.associationType. Docs on Associations
I also found an old stack overflow question which mentioned that calling something like Posts instanceof sequelize.Association.BelongsTo should work as well. When I call Posts.associations it only gives me the association as a key and value. {'Comments': 'Comments}
But neither method works. I seem to be able to access the rest of the model's attributes perfectly fine.
You are only seeing the toString() version of the output. It is more clear if you try:
console.log(Object.keys(models.Posts.associations));
This will give you an array of the keys of the associations, so you can use them to access more details:
console.log(Object.keys(models.Posts.associations.Comments));
You will then see that it has an associationType property which you can use to get the string value you are looking for. Comments is the name/key for the association which can be overridden with the as attribute in the definition.
// type = "BelongsTo"
var type = models.Posts.associations.Comments.associationType;

Could not resolve variable (may be a dynamic member)

I created variable with datatype object and created property for this object and asignt value to it.
var tileModel : Object = new Object();
tileModel.property = 10;
But I got warning in FDT Ide. Could not resolve variable (may be a dynamic member)
I have found that possibly solution might be use /*FDT_IGNORE*/ but I would rather solve it some clasic way.
Thank you for every answer
Use array notation as follows:
tileModel["property"] = 10;
To not have FDT flag this as an error, you'll need to adjust the parser to ignore it.
See screenshot:

Dynamically instantiate a typed Vector from function argument?

For a game I'm attempting to develop, I am writing a resource pool class in order to recycle objects without calling the "new" operator. I would like to be able to specify the size of the pool, and I would like it to be strongly typed.
Because of these considerations, I think that a Vector would be my best choice. However, as Vector is a final class, I can't extend it. So, I figured I'd use composition instead of inheritance, in this case.
The problem I'm seeing is this - I want to instantiate the class with two arguments: size and class type, and I'm not sure how to pass a type as an argument.
Here's what I tried:
public final class ObjPool
{
private var objects:Vector.<*>;
public function ObjPool(poolsize:uint, type:Class)
{
objects = new Vector.<type>(poolsize); // line 15
}
}
And here's the error I receive from FlashDevelop when I try to build:
\src\ObjPool.as(15): col: 18 Error: Access of undefined property type.
Does anybody know of a way to do this? It looks like the Flash compiler doesn't like to accept variable names within the Vector bracket notation. (I tried changing constructor parameter "type" to String as a test, with no results; I also tried putting a getQualifiedClassName in there, and that didn't work either. Untyping the objects var was fruitless as well.) Additionally, I'm not even sure if type "Class" is the right way to do this - does anybody know?
Thanks!
Edit: For clarification, I am calling my class like this:
var i:ObjPool = new ObjPool(5000, int);
The intention is to specify a size and a type.
Double Edit: For anyone who stumbles upon this question looking for an answer, please research Generics in the Java programming language. As of the time of this writing, they are not implemented in Actionscript 3. Good luck.
I have been trying to do this for a while now and Dominic Tancredi's post made me think that even if you can't go :
objects = new Vector.<classType>(poolsize);
You could go something like :
public final class ObjPool
{
private var objects:Vector.<*>;
public function ObjPool(poolsize:uint, type:Class)
{
var className : String = getQualifiedClassName(type);
var vectorClass : Class = Class(getDefinitionByName("Vector.<" + className + ">"));
objects = new vectorClass(poolsize);
}
}
I tried it with both int and a custom class and it seems to be working fine. Of course you would have to check if you actually gain any speed from this since objects is a Vector.<*> and flash might be making some implicit type checks that would negate the speed up you get from using a vector.
Hope this helps
This is an interesting question (+1!), mostly because I've never tried it before. It seems like from your example it is not possible, which I do find odd, probably something to do with how the compiler works. I question why you would want to do this though. The performance benefit of a Vector over an Array is mostly the result of it being typed, however you are explicitly declaring its type as undefined, which means you've lost the performance gain. So why not just use an array instead? Just food for though.
EDIT
I can confirm this is not possible, its an open bug. See here: http://bugs.adobe.com/jira/browse/ASC-3748 Sorry for the news!
Tyler.
It is good you trying to stay away from new but:
Everything I have ever read about Vector<> in actionscript says it must be strongly typed. So
this shouldn't work.
Edit: I am saying it can't be done.
Here see if this helps.
Is it possible to define a generic type Vector in Actionsctipt 3?
Shot in the dock, but try this:
var classType:Class = getDefinitionByName(type) as Class;
...
objects = new Vector.<classType>(poolsize); // line 15
drops the mic
I don't really see the point in using a Vector.<*>. Might as well go with Array.
Anyhow, I just came up with this way of dynamically create Vectors:
public function getCopy (ofVector:Object):Object
{
var copy:Object = new ofVector.constructor;
// Do whatever you like with the vector as long as you don't need to know the type
return copy;
}

Multi tenancy with Windsor

I need to implement multi-tenancy and i like the way it is solved here.
The problem implementing this scenario (in my project) is that the following code snippet
var handlerSelectors = windsorContainer.ResolveAll<IHandlerSelector>();
gives me something ( {Castle.MicroKernel.IHandlerSelector[0]}).
The following snippet should iterate through handlerSelectors but it's doing nothing !!
foreach (var handlerSelector in handlerSelectors)
{
windsorContainer.Kernel.AddHandlerSelector(handlerSelector);
}
In the debugger i can see i tries to set a value to var handlerSelector but it skips the for loop.
Am i missing something??
Thanks in advance
Mauricio Sheffer pointed me out how to correct the error! (see comments...or should i say i need a good pair of glasses?)