【发布时间】:2014-06-01 16:53:01
【问题描述】:
我在这里有一个非常艰巨的任务。我正在开发一个AngularJS 网络应用程序,它能够向我们项目的Restful Web Service 发送不同的HTTP 方法并接收JSON 响应。基本上是这样的:
您可以从此应用程序创建一些REST resource。假设是exam。要创建考试 - 您从可用资源列表中选择一个资源。这会触发一个函数,该函数向localhost:8080/STEP/api/explain/resorceName 发送请求并获取此资源的描述。描述如下:
http://jsonblob.com/534fc022e4b0bb44248d6460
收到响应后 - 我开始构建输入字段,如下所示(allFields - 此资源的字段对象数组,enumValues - 资源字段的枚举值,如果它是属性 isEnum = true):
<div ng-repeat="field in allFields">
<div ng-show={{!field.isEnum}}>
<p ng-show={{field.isRequired}}>{{field.name}}*: </p>
<p ng-show={{!field.isRequired}}>{{field.name}}: </p>
<input type="text" ng-model="updateEntityResource[field.name]" ng-change="getUpdateEntityAsText()"
class="form-control" placeholder="{{parseClassName(field.type)}}">
</div>
<div ng-show={{field.isEnum}}>
<p ng-show={{field.isRequired}}>{{field.name}}*: </p>
<p ng-show={{!field.isRequired}}>{{field.name}}: </p>
<select ng-model="updateEntityResource[field.name]" ng-change="getUpdateEntityAsText()" class="form-control">
<option></option>
<option ng-repeat="enumValue in field.enumValues" label={{enumValue.name}}>{{enumValue.ordinal}}</option>
</select>
</div>
</div>
现在,问题来了。我需要创建一个递归指令,它能够以上述方式为每个“restResourceName”不为空的资源字段生成字段。要获取所有字段,您只需向 localhost:8080/STEP/api/explain/restResourceName 发送请求并获得与上图类似的 JSON 响应,然后用于构建 HTML 元素以将值输入模型。
如何使用角度递归指令来实现?
【问题讨论】:
标签: javascript json angularjs rest recursion