【发布时间】:2017-02-10 05:25:56
【问题描述】:
我正在尝试处理表单中提交的数据对象,但我被卡住了。我在这个网站上做了一些研究,花了几个小时阅读,但我没有得到任何答案。我可以毫无问题地获取表单数据,问题是客户在两个或多个酒店登记客人时。在 pre 标签中,它将显示 hotel_name:{"hotelx", "hotely"}。我想将它作为 JSON 存储在我的住宿文件中,但是当我的控制器接收到表单数据对象时,如何闯入它并获得我需要的东西,以便我可以将它推送到文件中?
<div class=" col-md-12">
<div class="md-form">
<input type="text" id="Not_Listed" class="form-control" ng-model="lodgingRegistration.not_listed" placeholder="Enter hotel name if not listed below">
<label for="Not_Listed"></label>
</div>
<div class="md-form col-md-6" ng-repeat="x in lodging">
<input type="checkbox" id="{{x.hotel_name}}"
ng-model="lodgingRegistration.hotel_name[x.hotel_name]">
<label for="{{x.hotel_name}}">{{x.hotel_name}}</label>
</div>
</div>
<div class="text-center">
<button class="btn btn-deep-purple" ng- click="register(lodgingRegistration)">Submit</button>
</div>
<h3>Captured Form Data:</h3>
<pre>{{lodgingRegistration | json}}</pre>
这是我的控制器代码
$scope.register = function(lodgingRegistration){
// something must go here to break into the object/array before I push?
$scope.registered.push(lodgingRegistration);
console.log(lodgingRegistration);
}
这是我的显示,大部分作品,但我也无法访问文件中的虚拟数据,这是一个hotel_name数组
<tbody>
<tr ng-repeat="x in registered | filter:SearchHotel"
<th scope="row">{{$index +1}}</th>
<td>{{x.event_name}}</td>
<td>{{x.team_name}}</td>
<td>{{x.sport}}</td>
<td>{{x.hotel_name}}</td>
</tr>
</tbody>
我知道我需要更改访问方式
x.hotel_name
,我试过嵌套
ng-repeat with
y in x.hotel_name
但它没有工作。我想使用 Firebase 将其存储为 JSON,但如果我不能,我将不得不回到 PHP,我真的不想这样做,非常感谢任何帮助。
【问题讨论】: