【问题标题】:iphone child view inside rows on a for() statment in JS, appceleratorJS,appcelerator中for()语句的行内的iphone子视图
【发布时间】:2011-03-19 16:24:36
【问题描述】:

我正在 appcelerator 中制作一个 iPhone 应用程序,学生可以在其中查看他们的课程安排。

我有一个 JSON 响应,它为我带来了具有以下属性的教室:

  • 小时
  • 教授

所以一个例子是一个数组有这样的东西:

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

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

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


我收到这些参数并使用以下代码在UITableView 中显示它们:

   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;

        }

所以问题是这样的......

我如何分配给连续生孩子的每个班级(我指的是上面显示的大学教室)?

因此,当我单击行时,它会显示一个子视图,其中包含有关其教室的信息。我有关于教室的信息,我只想为每一行分配一个孩子。

【问题讨论】:

    标签: javascript iphone titanium appcelerator


    【解决方案1】:

    首先,您应该为行视图设置 hasChild 属性以显示该行有子视图。

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

    然后您可以打开一个新的windowview 来显示数据的详细信息,它应该在您的tableview 点击事件监听器中处理。

    【讨论】:

      【解决方案2】:

      这里有两件事,首先,您不希望每一行都有不同的 className,它应该对所有行都相同。

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

      其次要显示有关教室的特定信息,顺便说一句,我在上面提供的代码中没有看到任何教室信息,您只需将其作为属性传递给这样的行

      row.classRoomInfoURL = "class_one.js"
      

      处理行的事件监听器时

      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();
      

      });

      【讨论】:

        猜你喜欢
        • 2010-10-14
        • 1970-01-01
        • 2012-03-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-08-22
        相关资源
        最近更新 更多