Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/45.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Can';t在Tianium mobile应用程序中单击TableViewSection时查看Tableviewrow_Javascript_Iphone_Json_Titanium_Tableview - Fatal编程技术网

Javascript Can';t在Tianium mobile应用程序中单击TableViewSection时查看Tableviewrow

Javascript Can';t在Tianium mobile应用程序中单击TableViewSection时查看Tableviewrow,javascript,iphone,json,titanium,tableview,Javascript,Iphone,Json,Titanium,Tableview,我开发了一个基于以下树结构的应用程序: 默认值: <Alloy> <Window class="container"> <Require type="widget" src="com.drawermenu.widget" id="drawermenu"/> </Window> </Alloy> 类别 类别 类别 单击类别时: <Alloy> <Window class="

我开发了一个基于以下树结构的应用程序:

默认值:

<Alloy>
    <Window class="container">
        <Require type="widget" src="com.drawermenu.widget" id="drawermenu"/>

    </Window>
</Alloy>
  • 类别
  • 类别
  • 类别
单击类别时:

<Alloy>
    <Window class="container">
        <Require type="widget" src="com.drawermenu.widget" id="drawermenu"/>

    </Window>
</Alloy>
  • 类别
    • 子类别
      • 产品
  • 类别

  • 类别

有时:

<Alloy>
    <Window class="container">
        <Require type="widget" src="com.drawermenu.widget" id="drawermenu"/>

    </Window>
</Alloy>
  • 类别

  • 类别

    • 产品
  • 类别

在这里,我必须使用tableview来实现这个概念

是的,我创建了tableview,然后创建了tableviewsection。我添加了类别 在tableviewsection中。我已经在tableviewsection中创建了tableviewrow。如果单击了所选类别,则在这些tableviewrow中添加了子类别值。但有些类别有子类别。。。 有些类别没有子类别。直接有产品。所以你能解释一下吗

编辑:

<Alloy>
    <Window class="container">
        <Require type="widget" src="com.drawermenu.widget" id="drawermenu"/>

    </Window>
</Alloy>
我有以下代码:

    // create menu view
var data = [];

var v1 = Ti.UI.createView({
  height: '100%',
  width: '320dp',
  left: '0%',
  backgroundColor: '#212429'
});

$.drawermenu.drawermenuview.add(v1);

var tableView = Ti.UI.createTableView({
  height: '100%',
  width: '100%',
  separatorColor: '#111214',
  allowsSelection: true,
  style: Ti.UI.iPhone.TableViewStyle.GROUPED
});
v1.add(tableView);

var dataArray = [];
getCategoryList();

function getCategoryList() {
  var sendit = Ti.Network.createHTTPClient({
    onerror: function(e) {
      Ti.API.debug(e.error);
      alert('There was an error during the connection');
    },
    timeout: 10000,
  });
  sendit.open('GET', url + 'android_livedev/client/xxx.php?action=allCategory&category=all');
  sendit.send();
  sendit.onload = function() {
    var response = JSON.parse(this.responseText);
    if (response[0].success == 0) {
      tableView.headerTitle = response[0].message;
    } else {
      tableView.headerTitle = "";
      dataArray = [];
      for (var i = 0; i < response[0].data.length; i++) {
        var customsection = Ti.UI.createView({
          width: Ti.UI.FILL,
          height: Ti.UI.SIZE,
          opened: true,
          id: i,
          categorylist_category_id: response[0].data[i].categoryid,
          categorylist_level: response[0].data[i].category_level,
          backgroundcolor: '#fff',
          length: response[0].data.length,
        });

        var text = Ti.UI.createLabel({
          text: response[0].data[i].category,
          left: 20,
          id: i,
          categorylist_category_id: response[0].data[i].categoryid,
          categorylist_level: response[0].data[i].category_level,
          color: '#000'
        });
        customsection.add(text);

        row = Ti.UI.createTableViewSection({
          headerView: customsection,
        });
        dataArray.push(row);
        customsection.addEventListener('click', function(e) {
          categorylist_category_id = e.source.categorylist_category_id;
          categorylist_level = e.source.categorylist_level;
          categorylist_id = e.source.id;
          if (categorylist_level == "Y") {
            var subcategory = [];
            for (j = 0; j < response[0].data[categorylist_id].subcategorymm.length; j++) {
              var subcategory = Ti.UI.createTableViewRow({
                subcategorylist_category_id: response[0].data[categorylist_id].subcategorymm[j].categoryid,
                layout: 'horizontal',
                top: 5,
                width: "100%",
                backgroundcolor: '#000',
                height: Ti.UI.SIZE,
              });

              var subcategorytext = Ti.UI.createLabel({
                text: response[0].data[categorylist_id].subcategorymm[j].category,
                top: 5,
                width: Ti.UI.FILL,
                font: {
                  fontSize: '18dp'
                },
                color: '#040404',
                wordWrap: true,
                height: Ti.UI.SIZE,
                ellipsize: true
              });
              subcategory.add(subcategorytext);

            };

            row.add(subcategory);


          } else {
            from = "Product";
            var product = Alloy.createController('product').getView();
            product.open();
          }
        });
      };
      tableView.setData(dataArray);
    };
  };


}

var top10Screen = Alloy.createController('top10Screen').getView();
$.drawermenu.drawermainview.add(top10Screen);

Ti.App.addEventListener('settingImg', function(data) {
  $.drawermenu.showhidemenu();
});

$.sample.open();
这里列出了类别。但是如果我单击类别,它将列出子类别。但是我无法查看子类别。你能检查一下并给我一个解决方案吗

编辑:

<Alloy>
    <Window class="container">
        <Require type="widget" src="com.drawermenu.widget" id="drawermenu"/>

    </Window>
</Alloy>
在此for循环中:

 for(j=0;j<response[0].data[categorylist_id].subcategorymm.length;j++){

这意味着子类别在我的控制台窗口中打印得很好。但我无法查看tableviewrow。我知道我犯了一点小错误。所以你能找出错误并给我一个解决方案吗。

你的问题是真实的,你的代码看起来有点混乱。如果你想避免花费数小时来获得预期的结果,我建议你选择更有条理的方式。例如,尝试将当前代码拆分为多个具有精确目标的函数

我将尝试使用一些用于两级导航菜单的代码来提供帮助。逻辑是一样的,但是你必须自己添加第三层

构建菜单 我假设在您的xml中,有一个空的TableView正在侦听如下的点击(或单击)事件:

在初始化过程中,您可以调用一个函数,将第一级空部分添加到TableView中

要向这些部分添加新行,请定义
\u createRow
,它根据其
类型创建、填充并返回
Ti.UI.createTableViewRow

\u createRow=函数(数据,类型){
var row=Ti.UI.createTableViewRow();
//在此处使用某些内容填充行。。。
//在行中保存一些有用的信息
row.listId=data.id;
row.subItems=data.subItems;
//我们正在创建什么类型的行?
如果(类型==‘节点’){
//类别
row.isParent=true;
}
如果(类型=='child'){
//将行自定义为产品
row.backgroundColor='#2a2a2a';
}
//子类别可能有第三种类型
返回行;
};
然后在每个部分中添加一个
节点
行,该行是显示类别的父级,并保存一些信息,如类别id、类型及其子项(我们将在后面使用)

句柄单击事件(第1部分) 如果从TableView中获取事件,则有3种可能的情况:

  • 用户单击了类别->显示/隐藏子类别
  • 用户单击子类别->显示/隐藏产品
  • 用户单击产品->导航到产品
  • 相关代码在本文末尾,我将首先解释如何处理这些情况

    “开放”类别部分 如果该部分尚未打开,我们希望显示其中的内容。让我们定义一个函数
    \u openSection
    ,它将在刚刚单击的类别之后添加一个新的节。 然后,将尽可能多的元素添加到本节的子类别中

    function\u openSection(索引,父行){
    newSection=Ti.UI.createTableViewSection({
    索引:parentRow.section.index+1
    });
    _.each(parentRow.subItems,函数(item){
    添加(_createRow(项,'child'));
    });
    parentRow.opened=true;
    //可以在iOS上设置动画:
    $.menuTable.insertSectionAfter(索引,新闻节);
    //保存当前打开的节
    currentOpen=newSection;
    };
    
    “关闭”类别部分 反过来也是一样:一个已经打开的部分可以通过录音来关闭。让我们从
    表视图中删除目标部分

    \u closeSection=函数(索引,父行){
    currentOpen=null;
    parentRow.opened=false;
    var removed=$.menuTable.sections[index].rows.length;
    $.menuTable.deleteSection(索引);
    移除返回;
    };
    
    句柄单击事件(第2部分) 现在,您已经拥有了打开和关闭类别所需的一切,下面是处理该类别的代码:

    \u handleMenu=函数(evt){
    var justify=false,openIndex;
    //单击的部分已打开
    如果(evt.row.OPEN){
    返回_closeSection(evt.section.index+1,evt.row);
    }否则{
    /*关闭当前打开的部分,以便只有一个类别
    *同时打开(大大简化了解决方案)
    */
    如果(当前打开){
    parentSection=$.menuTable.sections[currentOpen.index-1];
    parentRow=parentSection.rows[0];
    
    如果(currentOpen.index请添加Alloy代码,您是否有两个
    窗口
    ?我注意到您将
    表格视图
    添加到a
    视图
    ,该视图也添加到
    win
    ,在上一条语句中,您打开了另一个窗口-->
    $.sample.open
    。如果您添加URL字符串,我也会很有帮助测试你的代码。@Zabady你能看看我更新的问题并给我一个想法或建议吗solution@Zabady你能看看我最新的问题并给我一个想法或解决方案吗