Get the row id in TableViewRow - titanium

The following code to print the "local" model in tableview, its working, now my problem is to fetch the row id or row detail by clicking the each row. I have attached the showDetail function on each row to get the row detail.But unable to get the row attch data. How can i achieve this please help me, I really appreciate your answers.
<TableView dataCollection="local">
<TableViewRow onClick="showDetail">
<View layout="horizontal">
<ImageView image="{image}" width="50" height="50"/>
<Label id="name" text="{title}"></Label>
</View>
</TableViewRow>
</TableView>
function showDetail(e){
console.log(e.index);
}

Have a look at the TableView API click Event:
http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.TableView-event-click
There are all properties: e.g. index=the number of the row
And have a look at row and rowData

Related

Titanium appcelerator how to update view inside listview?

I have an Appcelerator Titanium app to do, i have a Ti.UI.ListView with a view inside (view_one.xml):
...
<ListView onItemclick="getEvaluation" id="myLisview" defaultItemTemplate="templateLm" bottom="0" top="10" onItemclick="changePage" backgroundColor="white">
<Templates>
<Require id="lm_items" src="common/templateLm"/>
</Templates>
</ListView>
...
in common/templateLm :
<Alloy>
<ItemTemplate name="templatePageMission">
<View bindId="evaluate" height="10dp">
<Label text="evaluate"></Label>
</View>
<View bindId="stars" height="15dp"/>
</ItemTemplate>
</Alloy>
in view_one.js :
function getEvaluation(e){
switch(e.bindId){
case 'evaluate':
var item = e.section.getItemAt(e.itemIndex);
console.log(item) // <= this is empty ????
item.stars.backgroundColor = "red";
break;
}
}
and when click on the evaluate view I finally got:
undefined is not an object (evaluating item.stars.backgroundColor)
If anyone can help, this is great, anyway thanks for this great community.
You have assigned the itemclick event twice:
onItemclick="changePage"
and
onItemclick="getEvaluation"
So if you just use the latter one, it should catch the controller function correctly and the item should be updated correctly, since your controller code looks valid.

Star rating control in Titanium Alloy?

I need to get the feedback star ratings for 5 questions, I'm using titanium alloy mobile development. For the same reason I have used the star rating widget from the below link,
https://github.com/AppceleratorSolutions/AlloyWidgets/tree/master/starrating
From the above link there is only one set of stars, But I need to use the star ratings for 5 times. How can I do that. I need the following format
1. Question?
*****
2. Question?
*****
3. Question?
*****
4. Question?
*****
5. Question?
*****
The widget is working fine but the stars are displaying only for one question, I need the stars for all the five questions, below is my current output,
questionnaire.xml:
<Alloy>
<Window id="questionnaireWin" title="Plan India" platform="android,ios">
<View id="header">
<Label id="title">Feedback</Label>
</View>
<Label id="question1" class="question">1. Question 1?</Label>
<Require type="widget" src="starrating" id="widget" name="widget" />
<Label id="question2" class="question">2. Question 2?</Label>
<Require type="widget" src="starrating" id="widget" name="widget" />
<Button class="button" onClick="submitRatings">Proceed</Button>
</Window>
</Alloy>
Though, I'm using widget twice it is showing only once. Please help how to do this?
Else any easy way to do this using any plugins or something esle?
You have required the same widget tow times using the same id. you should define different id.
<Alloy>
<Window id="questionnaireWin" title="Plan India" platform="android,ios">
<View id="header">
<Label id="title">Feedback</Label>
</View>
<Label id="question1" class="question">1. Question 1?</Label>
<Require type="widget" src="starrating" id="widget1" name="widget" />
<Label id="question2" class="question">2. Question 2?</Label>
<Require type="widget" src="starrating" id="widget2" name="widget" />
<Button class="button" onClick="submitRatings">Proceed</Button>
</Window>
and the in you js file initialize widget1 & widget2 ...
$.widget1.init();
$.widget2.init();
EDIT you can test this example that i have created ...

Titanium Alloy get all label text value from xml

I want to console log all label text value displayed from my xml, And this is how I was doing to log the label Ti.API.info($.label.getText()); , but this code doesn't seem to work since this only works for only a single value from a variable. How I'm going to do this? Sorry,Just so noob enough. Thanks!
<TableView id="table" dataCollection="person">
<TableViewRow id="row">
<Label id="label" text="{name}"></Label>
</TableViewRow>
</TableView>
from the Appcelerator documentation http://docs.appcelerator.com/titanium/latest/#!/guide/Alloy_Data_Binding
dataTransform: specifies an optional callback to use to format model attributes. The passed argument is a model and the return value is a modified model as a JSON object.
<TableView id="table" dataCollection="person" dataTransform="dumpText" >
<TableViewRow id="row">
<Label id="label" text="{name}"></Label>
</TableViewRow>
</TableView>
So we can use this method to dump whatever is being added to the list
function dumpText(model) {
// model to a JSON object
var o = model.toJSON();
Ti.API.info(o.name);
return o;
}

dynamic data for each TableViewRow

I'm using alloy (markup and models) to construct a tableview, Everything works perfect
<Collection src="spot" />
<Window>
<TableView id="spotTableView" dataCollection="spot">
<TableViewRow title="{name}">
<View class="header-view">
<Label class="title-header" text="{name}"/>
<Label class="desc-header" text="{desc}"/>
</View>
<View class="fixed-view">
<ImageView class="image" image="{logo}"/>
<View class="info-view">
<Label class="green-label" text="{cost}"/>
<Label text="{minimum}"/>
</View>
</View>
</TableViewRow>
</TableView>
</Window>
But I have a question: How I can modify dynamic data form for each tableviewrow? I need to change the colors of the labels depending on the data that brings each model in the collection. For example, if the cost is 0 that the label "cost" is green, but if the cost is 100 then the color of the label is red.
I guess this must realizarce on the controller, but I would not like create the tableviewrow out of view, because they do not want to miss the advantages of data bindings
Add a field containing the color to the model, and bind the label's color to it.

How to make a button event in pure xaml

I have this code
<Image Name="LightOn_BMP" Source="Res/LightOn.bmp" Canvas.Left="150" Canvas.Top="10" />
<Image Name="LightOff_BMP" Source="Res/LightOFF.bmp" Canvas.Left="150" Canvas.Top="10" />
<Button Canvas.Left="215" Canvas.Top="150" Click="PowerOn">
<Image Name="SwitchDown_BMP" Source="Res/SwitchDown.bmp" />
</Button>
<Button Canvas.Left="215" Canvas.Top="150" Click="PowerOff">
<Image Name="SwtichUp_BMP" Source="Res/SwitchUp.bmp" />
</Button>
And I want in pure XAML to make the PowerOn event to change so that LightOn.bmp is visible and LightOff.bmp is hidden and hide the Switchdown.bmp picture/button
Then I should be able to figure out how to make the event for the PowerOff
Simply put, you can't. The whole idea behind WPF is that you should separate behavior from display. So, at least without making some crazy black magic, you won't be able to change the state of the Image object (visible to false).