开发者

iphone child view inside rows on a for() statment in JS, appcelerator

I'm making an iPhone app in appcelerator where students can see their classes schedule.

I have a JSON response where it brings me the classrooms with these attributes:

  • day
  • hour
  • class
  • professor

So an example would be an array having something like this:

[monday,8:00,math,sofia heelter]

[monday,10:00,biology,andrea sulivan]

[friday,8:00,math,sofia heelter]


I receive those parameters and show them in a UITableView with this code:

   for (var i = 0; i < response.classrooms.lenght; i++)
        {
        var day= response.classrooms[i].day;
        var hour= response.classrooms[i].hour;
        var materia= response.classrooms[i].class;
        var professor= response.classrooms[i].professor;

            var row = Titanium.UI.createTableViewRow({height:'auto'});
            var post_view = Titanium.UI.createView({
                height:'auto', 
                layout:'vertical',
                top:5,
 开发者_运维技巧               right:5,
                bottom:5,
                left:5
            });
            var text= Titanium.UI.createLabel({
                text:text,

                top:0,
                left:0,
                bottom:15,
                height:48,
                width:300,
                font:{fontFamily:'helvetica',fontSize:20}
            });
            post_view.add(text);
            // Add the post view to the row
            row.add(post_view);
            // Give each row a class name
            row.className = "item"+i;
            // Add row to the rowData array
            rowData[i] = row;

        }

So the question is this...

How can I assign to each class (I mean the university classroom that is shown above) which is in a row to have a child?

So when I click on the rows it brings up a child view with the info regarding their classrooms. I have the info about the classroom I just want to assign a child to every row.


Firstly you should set hasChild property for the row view to show that row has child.

var row = Titanium.UI.createTableViewRow({height:'auto',hasChild:true});

Then you can open a new window, or view to show the details of the data and it should be handle in your tableview click event listener.


Two things here, first off, you do not want to have a different className for each row, it should be the same for all of the rows.

 // Give each row a class name
 row.className = "studentRowClass";

Secondly to show specific information about a class room, BTW I dont see any classroom information in the code provided above, you would just pass it as a property to the row like this

row.classRoomInfoURL = "class_one.js"

when handling the eventListener for the row

table.addEventListener('click', function(eventData) {
Ti.API.debug(eventData);
var win = Ti.UI.createWindow({
    title:"CLASS ROOM INFO",
    backgroundColor: '#fff',
    width:'100%',
    height:'100%',
    url: eventData.rowData.classRoomInfoURL,
});
win.open();

});

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜