How to use item renderer to view multiple fields? - json

Our app contacts the server, and get a json based array, each item has:
First_Name
Last_Name
Image_Url
So, how to use the item renderer so that we can use custom data template to view name and image?
Also, can we have access to the json item being rendered from inside the renderer code?
Any examples would be highly appreciated.

http://help.adobe.com/en_US/flex/using/WS77c1dbb1bd80d3836ecbb5ec129ec77b1e1-8000.html
just above the 'Controlling the background display of an item renderer' section, there is a custom itemrenderer example, you can use it.

Find below link to add custom item renderer
http://www.adobe.com/devnet/flex/videotraining/exercises/ex4_03.html

Related

separating data in an array for display in Flex

I'm new to flex/flash builder, i need to read in data from a text document, then slice it into pieces i set out in my custom class.
all of this so far worked
var theCustomer:Customer=new Customer(name,address,phoneNo,comment,custNo);
custArray.addItem(theCustomer);
So now what i want to do is display only the name from each entry of the array into a combobox - and then on close it will display all the details into a list box
If i just bind the custArray to the combobox it displays name:address:phoneNo:comment:custNo as i set it out, but like i said i want only the name so how do i separate the name from each Customer entry in the array ??
Any help you be awesome and thanks in advance !!!
If I'm understanding your question correctly, I think you want to set the labelField property on the combobox. This specifies the field in the source data objects to use in the label.
<s:ComboBox dataProvider="{custArray}" labelField="name"/>
The ComboBox has several ways to specify what it should use as the "label" for each item in the dataProvider:
By default, if the elements in the dataProvider has a property named label, and that property contains a String it will display that value.
ComboBox has a labelField property that you can use to tell it where to find the "label" for each item. In your case, you could set the labelField to "name"
ComboBox has a labelFunction property that allows you to use a function (that you write) to specify what text should be displayed for each item.
I suggest using the the labelField, as that seems the most straight forward in this case:
<s:ComboBox dataProvider="{custArray}" labelField="name" />

different item style for items in listbox

As listbox only accept string as items, is there a way to add items with different style? Is there any class to do this?
Ex:
Item1 in red
Item2 in green
Thanks.
var tree = app.createTree();
tree.addItem(app.createTreeItem(
app.createLabel("Tree Item 1").setStyleAttribute("color","green")));
tree.addItem(app.createTreeItem(
app.createLabel("Tree Item 2").setStyleAttribute("color","red")));
Edit: Sorry you said List but I read Tree for some reason.
No, this cannot be done, because the underlying browser list widgets don't support it. It's possible to achieve something roughly similar using HtmlService and jQuery, but not in UiApp.

Accessing ListBox selected item via UiApp.getActiveApplication().getElementByID()

Currently I am using UiService to create a form and I uses ListBox, from what I understand to pass a value via handler will be something like e.parameter.[Name of ListBox] to access the selected item.
Does anyone know is it possible to use like app.getElementById([Name of ListBox]) to access the selected item. The reason I am using this method is because my list of ListBox-es are dynamic.
I spent some time looking for this answer as well, but finally I tried one idea and it worked.
You can use e.parameter as an array so you can these two will give the same:
e.parameter.LIST_BOX_NAME
and
e.parameter['LIST_BOX_NAME']
So in the second sample any dynamic list box ID can be used. I use same handler for all added dropdown list and have this code to check what dropdown was changed and what value it has now:
if (e.parameter[e.parameter.source] == 'a'){
To change the content of the listBox you can use app.getElementById('ID of the listBox'), from there you can clear() and addItems again but you cannot read the listItems.
When I need to do this I usually store the list of items somewhere else, in a place that I can read anytime, for example the list of items can be stored as a string in the listBox tag itself so I have all items at hand to repopulate the listBox after I have clear it.

It is possible to add to Unordered List during runtime

I have a simple HTML page with an Unordered list. Is it possible to have an input field where you could add more to the list and it would be saved after you submitted it. What I would like to add would be the content inside of an <li> tag as well as the <li> tags themselves.
Thanks,
Here is a jsfiddle with a demo of what I think you want to achieve: http://jsfiddle.net/mvJNq/25/
Note that I can not answer as to how you should do this on the server, as that depends on how your serverside code, database etc is set up. However, if all you want is to display it as HTML and not have it saved as the user navigates away, you won't need the Submit button at all - then you just need the "Add" functionality.
Yes, it is possible - no, it will not be pretty. Here is what you would do:
create your base form with any default list items/inputs
use jQuery/JavaScript to bind an event handler to a button that you click when you want to add another item (alternatively, you could skip this step and just have another item appear by default)
on your event (be it checking that all input boxes have user-entered text, or the click event in step two) add another list item using jQuery.append(...)
ensure that you have a hidden input field to be used as a "counter" to keep track of the total number of list items and increment the value of this counter each time you add a new list item (note: you may need to use the ParseInt() method, depending on how you design the code for this field)
the page that is receiving the form's inputs should first read the hidden field so that it knows how many items to add, and then you should loop through the items (for or while loop) to add them correctly
Note: I don't know what Server-Side language you are using to handle receiving the form so step 5 is a fairly generic and universally viable option
Sure, it's possible.
The complexity of this comes in when you want to "save" the items. If the user leaves the page and comes back later will that data be available? If so, you will need a database like mySQL or similar. The li tags can be stored as well, but why?
If you just need that information available in that session you can store in a JavaScript variable and have it loop through the variable and spit them out as <li>'s
If you did want to use an add button instead of submit:
$('#addButton').click(function(){
var savedContent = $('#input').val();
}
To create + insert the <li>you can use javascript to create the element and append it to the ul. If you have more than one ul change the index:
var content = document.createElement('li');
content.innerText = savedContent;
document.getElementsByTagName('ul')[0].appendChild(content);

How to output a "." right after an object in Razor

I have an object called item, item has a property itemId. I am trying to build up a url that has the itemId followed by .html... so it would look like "myNiftyItem-123456.html"
#item.itemTitle-#item.itemId.html
Doesn't work as it thinks ".html" is a property or method of itemId. How do I get that to work?
You need to make an explicit code nugget: #item.itemTitle-#(item.itemId).html