2

我想从 Proteus 库生成级联资产。我是 android 开发的新手,在@adithya(Proteus 的开发人员)的帮助下,我设法用库构建了一个动态视图。

我想要简单的是假设有一个单选按钮的值是单选按钮我需要在单选按钮的下方添加更多资产

它就像你有孩子?如果是,下面应该加载多少个子文本框

像这样

{
  "survey":[
    {
      "value" : "What's your name?",
      "type" : "TextView",
      "cascade" : "0",
      "show" :"true",
      "survey" : "",
      "id" : "1"
    },
    {
      "value" : "What's your age?",
      "type" : "TextView",
      "cascade" : "0",
      "show" :"true",
      "survey" : "",
      "id" : "2"
    },
    {
      "value" : "Do you have any children?",
      "type" : "SelectionController",
      "cascade" : "1",
      "show" :"true",
      "id" : "3",
      "option" : [
        {
          "value": "YES",
          "cascade": "1",
          "type": "option",
          "show": "false",
          "id" : "3.1",
          "survey": [
            {
              "value" : "How many children?",
              "type" : "TextView",
              "cascade" : "0",
              "show" :"false",
              "id" : "3.1.1",
              "survey" : ""
            },
            {
              "value" : "How many are married",
              "type" : "TextView",
              "cascade" : "0",
              "show" :"false",
              "id" : "3.1.2",
              "survey" : ""
            }
          ]
        },
        { "value": "No",
          "cascade": "0",
          "type": "option",
          "show": "false",
          "id" : "3.2",
          "survey": ""
        }
      ]
    },
    {
      "value" : "What's your address?",
      "type" : "TextView",
      "cascade" : "0",
      "show" :"true",
      "id" : "4",
      "survey" : ""
    },
    {
      "value" : "What is your status?",
      "type" : "SelectionController",
      "cascade" : "1",
      "id" : "5",
      "show" :"true",
      "option" : [
        {
          "value" : "Graduate",
          "type" : "option",
          "cascade" : "1",
          "id" : "5.1",
          "show" :"false",
          "survey" : [
            {
              "value" : "Which year?",
              "type" : "TextView",
              "cascade" : "0",
              "show" :"false",
              "id" : "5.1.1",
              "survey" : ""
            },
            {
              "value" : "Which faculty?",
              "type" : "TextView",
              "cascade" : "0",
              "show" :"false",
              "id" : "5.1.2",
              "survey" : ""
            }
          ]
        },
        {
          "value" : "Undergraduate",
          "type" : "option",
          "cascade" : "1",
          "show" :"false",
          "id" : "5.2",
          "survey" : [
            {
              "value" : "where are you studying?",
              "type" : "SelectionController",
              "cascade" : "1",
              "show" :"false",
              "id" : "5.2.1",
              "option" : [
                {
                  "value" : "APIIT",
                  "type" : "option",
                  "cascade" : "1",
                  "show" :"false",
                  "id" : "5.2.1.1",
                  "survey": [
                    {
                      "value" : "What is your GPA?",
                      "type" : "TextView",
                      "cascade" : "0",
                      "show" :"false",
                      "id" : "5.2.1.1.1",
                      "survey" : ""
                    },
                    {
                      "value" : "How was APIIT?",
                      "type" : "TextView",
                      "cascade" : "0",
                      "show" :"false",
                      "id" : "5.2.1.1.2",
                      "survey" : ""
                    }
                  ]
                },
                {
                  "value" : "SLIIT",
                  "type" : "option",
                  "cascade" : "0",
                  "show" :"false",
                  "id" : "5.2.1.2",
                  "survey" : ""
                },
                {
                  "value" : "UCSC",
                  "type" : "option",
                  "cascade" : "1",
                  "show" :"false",
                  "id" : "5.2.1.3",
                  "survey": [
                    {
                      "value" : "How long being in UCSC?",
                      "type" : "TextView",
                      "cascade" : "0",
                      "show" :"false",
                      "id" : "5.2.1.3.1",
                      "survey" : ""
                    },
                    {
                      "value" : "How is UCSC?",
                      "type" : "TextView",
                      "cascade" : "0",
                      "show" :"false",
                      "id" : "5.2.1.3.2",
                      "survey" : ""
                    }
                  ]
                },
                {
                  "value" : "UOM",
                  "type" : "option",
                  "cascade" : "0",
                  "show" :"false",
                  "id" : "5.2.1.4",
                  "survey" : ""
                }
              ]
            }
          ]
        }
      ]
    },
    {"value" : "Are you tired of studying?",
      "type" : "SelectionController",
      "cascade" : "0",
      "show" :"true",
      "id" : "6",
      "option" : [
        {
          "value" : "YES",
          "type" : "option",
          "cascade" : "1",
          "show" :"false",
          "id" : "6.1",
          "survey": ""
        },
        {
          "value" : "NO",
          "type" : "option",
          "cascade" : "0",
          "show" :"false",
          "id" : "6.2",
          "survey" : ""
        }
      ]
    }
  ]
}
4

1 回答 1

0

如果您正在寻找数据驱动视图,则该children属性可以是绑定对象,如下例所示

{
  "type": "LinearLayout",
  "orientation": "horizontal",
  "children": {
    "@": {
      "collection": "@{user.tags}",
      "layout": {
        "type": "LinearLayout",
        "orientation": "horizontal",
        "data": {
          "tag": "@{user.tags[$index]}"
        },
        "children": [
          {
            "type": "TextView",
            "text": "@{tag.title}"
          }
        ]
      }
    }
  }
}

collection必须是 json 数组。

collection是数据集,即数据数组中有多少次项目。

layout必须是布局定义或参考

为集合中的每个项目充气的布局。注意布局中的data属性和使用。$index

这将适用于如下数据集:

{
  "tags": [
    {
      "title": "alpha"
    },
    {
      "title": "beta"
    },
    {
      "title": "gamma"
    },
    {
      "title": "delta"
    },
    {
      "title": "niner"
    }
  ]
}
于 2018-01-02T09:25:46.493 回答