我从我的数据库中获取信息,并试图找出在应用程序中显示它的最佳方式。
这是我的数据库信息
[{" form_input_id":" 1"" form_id":" 6""标题&#34 ;: "请输入您的房间号码?"," input_type":" text","标识符":"房间" ,"选择":" s:0:\" \&#34 ;;","标题":"代客请求&# 34;},{" form_input_id":" 2"" form_id":" 6""标题&#34 ;: "请输入任何评论或反馈。"," input_type":" textarea","标识符":"反馈" ;,"选择":" s:0:\" \&#34 ;;","标题":"代客请求& #34;},{" form_input_id":" 3"" form_id":" 6""标题" :"请选择办公室"," input_type":"选择","识别":"办公室",&# 34;选择":" s:19:\"销售,预订\&#34 ;;","标题":"代客请求&# 34;},{" form_input_id":" 18"" form_id":" 6""标题&#34 ;: "姓氏","输入_type":"文本"" IDENTIFER":"姓氏""选择":" S:0:\ " \";","标题":"代客请求"},{" form_input_id":" 19& #34;," form_id":" 6","标题":"汽车类型"," input_type" :"选择"" IDENTIFER":" Car_type""选择":" S:20:\"别克,奥尔兹,法拉利\";","标题":"代客请求"}]
除了选择之外,我能够以我想要的方式拉动所有东西。我正在尝试创建动态表单,需要创建一个显示选项的选择。
我现在的控制人员:
controller('FormCtrl', function($scope, $ionicLoading){
// Grab Form
var form = angular.fromJson(window.localStorage.getItem('form'));
// Set Title
$scope.title = form[0].heading;
// Send Form Data
$scope.forms = form;
})
我的观点:
<ion-view title="Form" hide-nav-bar="true">
<ion-header-bar align-title="left" class="bar-dark">
<div class="buttons">
<a href="#/lobby" class="button button-dark">Cancel</a>
</div>
</ion-header-bar>
<ion-content id="dynamic" scroll="true" padding="true">
<h2 class="text-center">{{title}}</h2>
<form>
<div ng-repeat="form in forms">
<label>{{form.title}}</label>
<div ng-if="form.input_type == 'text'">
<input type="text" name="{{form.identifier}}" />
</div>
<div ng-if="form.input_type == 'time'">
<input type="time" name="{{form.identifier}}" />
</div>
<div ng-if="form.input_type == 'textarea'">
<textarea name="{{form.identifier}}"></textarea>
</div>
<div ng-if="form.input_type == 'select'">
<select name="{{form.identifier}}">
NEED TO FIGURE HOW TO DISPLAY CHOICES AS OPTIONS
</select>
</div>
</div>
</form>
</ion-content>
答案 0 :(得分:0)
您需要从字符串中解析您的选项。这样的事情:
angular.forEach($scope.forms, function(item){
item.options=item.choices.split('"')[1].split(',');
});
并在选择中使用ng-options:
<select name="{{form.identifier}}" ng-options="choice for choice in form.options" ng-model="Your model here"></select>