Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.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
使用自定义json创建角度表单并获取数据_Json_Angularjs_Angularjs Directive_Angularjs Scope - Fatal编程技术网

使用自定义json创建角度表单并获取数据

使用自定义json创建角度表单并获取数据,json,angularjs,angularjs-directive,angularjs-scope,Json,Angularjs,Angularjs Directive,Angularjs Scope,嗨,我正在使用angular js构建我的应用程序。我在生成动态表单时遇到一个问题。 我的json是: { lines :[ { fields:[{ fieldType : "input", labelName : "Test Label", modelName : "testInput" },{ fieldType : "se

嗨,我正在使用angular js构建我的应用程序。我在生成动态表单时遇到一个问题。 我的json是:

{
   lines :[ {
          fields:[{
               fieldType : "input",
               labelName : "Test Label",
               modelName : "testInput"
            },{
               fieldType : "select",
               labelName : "Test Label",
               options : "['opt1','opt2','opt3']",
               modelName : "testSelect"
             },{

               fieldType : "checkbox",
               labelName : "Test Label",
               modelName : "testCheckbox",
               options : '[{'key':'key1','value':'value1'}]"
     }]
}
这只是示例json。在实时方面,它是更复杂的类型。我为所有Html元素创建了单独的组件,如“输入”、“选择”、“复选框”、“收音机”。。。 我对所有输入元素使用指令。我将从表单的父范围到指令的一些细节。 例如:

主要指令

<ui-form form-option='uiFormOption'></ui-form>
Above is the main directive. i am passing above json in this Main Directive.

以上是主要指示。我在这个主指令中传递了上面的json。
在指令内部,我迭代所有行并调用相应的指令,以根据字段类型填充组件

在这里,Html组件指令正在创建独立的作用域,我需要这一点

从中保存时,需要获取ParentScope中单个对象中的所有数据 差不多 $scope.myFormData={}//父作用域控制器。
单击“保存”时,必须收集所有数据。我的问题是child指令中的$scope。因此,模型映射不知道父对象。如何做到这一点…

我不确定我是否正确理解了你的问题,但有两件事突然出现在我的脑海中,我确信你尝试过,但以防万一:

1-由于您能够将数据获取到html组件,因此可以将数据直接绑定到您从中收集数据的对象,并且由于数据在任何地方都可以访问,因此您可以使用它格式化您需要的任何响应

2-如果没有其他选项可用,您可以使用$scope。$root,我知道这不是最好的选择,但获得所有元素的共享作用域始终是一个难题


我希望这是您正在寻找的,如果不是,请发表评论。

如果您需要显示动态表单,那么通过API获取此类json对象:

{
"status": "true",
"statusCode": 200,
"response": [
    {
        "sort_order": 0,
        "control_name": "ion-select",
        "label": "Select master OLT",
        "type": "select",
        "placeholder": "Select master OLT",
        "name": "E0selectoption_master_olt",
        "readonly": "True",
        "required": "required",
        "maxlength": "",
        "minlength": ""           
    },
    {
        "sort_order": 1,
        "control_name": "ion-select",
        "label": "Select OLT port",
        "type": "select",
        "placeholder": "Select OLT port",
        "name": "E1selectoption_olt_port",
        "readonly": "True",
        "required": "required",
        "maxlength": "",
        "minlength": ""           
    },
    {
        "sort_order": 2,
        "control_name": "ion-select",
        "label": "Select Parent node",
        "type": "select",
        "placeholder": "Select parent node",
        "name": "E2selectoption_parent_node",
        "readonly": "True",
        "required": "required",
        "maxlength": "",
        "minlength": "",
        "is_dependent": "true",
        "masters": "gis_node",
        "value": ""           
    },
    {
        "sort_order": 3,
        "control_name": "ion-select",
        "label": "Select child node",
        "type": "select",
        "placeholder": "Select child node",
        "name": "E3selectoption_child_node",
        "readonly": "True",
        "required": "required",
        "maxlength": "",
        "minlength": "",
        "is_dependent": "true",
        "masters": "gis_node",
        "value": ""          
    },
    {
        "sort_order": 4,
        "control_name": "button",
        "label": "submit",
        "type": "submit",
        "placeholder": "",
        "name": "E4submit_btnsubmit",
        "readonly": "False",
        "required": "required",
        "maxlength": "",
        "minlength": "",
        "is_dependent": "false",
        "masters": "",
        "value": ""
    }
]
}
在给定的JSON格式响应中。 因此,您可以轻松地将这些数据与我们的html绑定