How to access a Dictionary from mx:repeater in flex? - actionscript-3

I'd like to create repeated Labels for a predefined key-value list. I defined this list as a Dictionary as follows:
private static var logos:Dictionary = new Dictionary; {
logos[0] = "test0";
logos[17] = "test17";
}
Now I'm trying to fill the repeater. I know the following does not work with .key and .value, but how could I do this in flex/as?
<mx:Repeater id="repeaterId" dataProvider="{logos}" >
<s:Label value="#{repeaterId.currentItem.key}" label="#{repeaterId.currentItem.value}" />
</mx:Repeater>

Related

POSTMAN - Save a property value from a JSON response

I am new to both JSON and Postman(as of yesterday).
I'm trying to do something very simple, I've created a GET request which pulls in a list of forms in a JSON response. I want to take this response and get the first "id" token and place it in a variable.
I am using a global variable but would like to use a collection variable if possible. Either way here is what I am doing.
I've tried several things, most recently this:
var jsonData = JSON.parse(responseBody);
postman.setGlobalVariable("id", jsonData.args.id);
As well as this:
pm.test("GetId", function () {
var jsonData = pm.response.json();
pm.globals.set("id", jsonData.id);
});
Response code looks like this:
{
"forms":[
{
"id":"3197239",
"created":"2018-09-18 11:37:39",
"db":"1",
"deleted":"0",
"folder":"151801",
"language":"en",
"name":"Contact Us",
"num_columns":"2",
"submissions":"0",
"submissions_unread":"0",
"updated":"2018-09-18 12:02:13",
"viewkey":"xxxxxx",
"views":"1",
"submissions_today":0,
"url":"https://xxx",
"data_url":"",
"summary_url":"",
"rss_url":"",
"encrypted":false,
"thumbnail_url":null,
"submit_button_title":"Submit Form",
"inactive":false,
"timezone":"US/Eastern",
"permissions":150
},
{
"id":"3197245",
"created":"2018-09-18 11:42:02",
"db":"1",
"deleted":"0",
"folder":"151801",
"language":"en",
"name":"Football Draft",
"num_columns":"1",
"submissions":"0",
"submissions_unread":"0",
"updated":"2018-09-18 12:11:54",
"viewkey":"xxxxxx",
"views":"1",
"submissions_today":0,
"url":"https://xxxxxxxxx",
"data_url":"",
"summary_url":"",
"rss_url":"",
"encrypted":false,
"thumbnail_url":null,
"submit_button_title":"Submit Form",
"inactive":false,
"timezone":"US/Eastern",
"permissions":150
}
]
}
This would get the first id:
pm.globals.set('firstId', _.first(pm.response.json().forms).id)
That would get the first in the array each time so it would set a different variable it that response changed.
The test that you created was nearly there but the reference needed to go down a level into the forms array:
pm.test("GetId", function () {
var jsonData = pm.response.json()
pm.expect(jsonData.forms[0].id).to.equal("3197239")
pm.globals.set("id", jsonData.forms[0].id)
})
The [0]is referencing the first id in the first object within the array. For example [1] would get the second one and so on.
You currently cannot set a collection level variable using the pm.* API - These can only be added manually and referenced using the pm.variables.get('var_name') syntax.
Edit:
In the new versions of the desktop app you can set variables at the Collection level using pm.collectionVariables.set().
Based on the name or any other attribute if you want to set the id as a global variable then this is the way.
for(var i=0; i<jsonData.forms.length; i++)
{
if (jsonData.forms[i].name==="Contact Us")
{
pm.environment.set("id", jsonData.forms[i].id);
}
}

How to convert multiple array item objects to single set of array

i have array like this
$scope.array1=[[Name:'Madhu'],[Name:'Vijay'],[Name:'Srinu']]
how to convert this array to this format,
i want to pass this array in columns option(in dx datagrid columns option)
so i want array format like this
$scope.array2=['Maadhu','vijay','srinu']
you could use the map extension on arrays in javascript:
$scope.array2 = $scope.array1.map(function(item) {
return item.Name;
});
you can use the map function:
$scope.array2 = $scope.array1.map(x = x.map(y => y.Name));

How to pass dynamic values as field name for an array collection in flex 3

public function Adddynamic_values(val:String):void
{
for(var i:int=0;i<Gridvaltest.length;i++)
{
Gridvaltest.setItemAt({label:"A",number:"1",val:val},i);
}
}
This is my code. Now i want to know how to add dynamic value as field name for an array collection. Is it possible or any other way to do like this?
If we are passing the "val" value like mentioned above example
it cosidered as string ie ( I have attached little bit of code for better understand)
[1] (Object)#4
label = "A"
number = "1"
val = "233.5"
I got this was the output. But i want like this ( if the dynamic value will be "val" = 255 )
[1] (Object)#4
label = "A"
number = "1"
255 = "233.5"
Change your parameter val into something other than val like ""value".
public function Adddynamic_values(value:String):void
{
for(var i:int=0;i<Gridvaltest.length;i++)
{
Gridvaltest.setItemAt({label:"A",number:"1",val:value},i);
}
}
This should do the trick.

Parse Complex Structure of XML

I want to show data before parsing Local XML but don't know how?I tried it by using this
XDocument loadedData = XDocument.Load("People.xml");
var data = from query in loadedData.Descendants("array")
select new Person {
Name = (string)query.Element("string"),
};
listBox1.ItemsSource = data;
but it shows me only one element.
XML is:
<?xml version="1.0" encoding="UTF-8"?>
<dict>
<key>Categories</key>
<array>
<string>Playing baseball</string>
<string>Driving a car</string>
<string>Getting dressed</string>
<string>Eating a hamburger</string>
<string>Tying shoelace</string>
</array>
</dict>
I want to parse all string element.
This should work. You want to iterate the elements within the array element, so we call Descendants("array").Elements(). There's no need to cast query.Value to a string as the value property is returned as a string.
XDocument loadedData = XDocument.Load("People.xml");
var data = (from query in loadedData.Descendants("array").Elements()
select new Person
{
Name = query.Value,
}).ToList();
listBox1.ItemsSource = data;
The Element(System.Xml.Linq.XName) method only returns one element--the first child element with the specified name. Use the Elements(System.Xml.Linq.XName) overload instead, which returns a collection of all elements whose name is the specified name.
Try this code:
XDocument loadedData = XDocument.Load("People.xml");
// Get all the <string /> elements from all th
var data =
from query in loadedData.Descendants("array")
from stringElem in query.Elements("string")
select new Person { Name = (string)stringElem.Value };
listBox1.ItemsSource = data;

dropdowlist [object object]

I discover with dropdownlist.
Indeed I load data by a query to mysql Database.
But in mysql one record has empty field.
And in this case flex display [object object] instead of ' '.
[Bindable] private var DP_CLASSES:ArrayCollection;
<s:DropDownList id="dpClassTT" width="77"
dataProvider="{DP_CLASSES}"labelField="Nom"
/>
// DataProvider sample
<TypesTT>
<TypeTT>
<Nom> </Nom>
</TypeTT>
<TypeTT>
<Nom>AppA</Nom>
<TypeTT>
<TypesTT>
The line [Objet object] appear on dropdownlist even if name is empy (like record one).
Do you know how to solve that?
Thanks
All I can say from the limited information you have posted here is that you need to set the labelField of the dropdownlist.
You can do this in mxml like
<s:DropDownList dataProvider="{myQuery}" labelField="colName" />
or, you set a labelFunction like:
<s:Script>
private function toLabel(item:Object):String {
return item["colName"].toString();
}
</s:Script>
<s:DropDownList dataProvider="{myQuery}" labelFunction="toLabel" />
EDIT after you've updated your question, I believe it is better to use the labelFunction.
Your labelFunction would be something like this:
function toLabel(item:Object):String {
var str:String=item["Nom"] as String;
if(str==null || str==undefined) {
str="";
}
return str;
}
We need to do this because the empty tag Nom is taken as an XMLList object in AS3, which is why it is necessary to cast it.