我需要提交ng-repeat指令下的表单。我以JSON格式获取正确的数据,但是当我执行insert查询时,它会输出最后的数据。
例如:查看我的代码
在视图中:
<div class="row" ng-init="get_membershipPlans()">
<div class="col-md-4" ng-repeat="x in plans" >
<div class="table-columns">
<form method="post" ng-submit="insert_data()">
<ul class="price height-price">
<li class="grey" ng-model="planDetails.price = x.price">${{x.price}}/ year</li>
<li ng-repeat="y in x.plansdetails">
{{y.feature_name}}
</li>
{{planDetails | json}}
</ul>
</form>
</div>
</div>
</div>
在角度控制器中:
$scope.insert_data = function () {
Data.insertData($.param($scope.planDetails)).success(function (data) {
$scope.planDetails = data;
});
};
在服务中:
this.insertData = function($data) {
return $http.post(site_url + "FunctionalController/inserttData" , $data);
};
在FunctionalController中:
public function inserttData() {
$tablename = 'ult_book_camp';
$rs = $this->db->insert($tablename, $_POST);
if ($rs) {
echo json_encode(array('status' => '1','msg' => 'You have booked camps successfully'));
} else {
echo json_encode(array('status' => '0', 'msg' => 'No Result Found'));
}
}
在视图中,使用ng-repeat,当我以json格式打印数据时,它会显示三个块,得到这样的结果{&#34; plan_id&#34;:&#34; 1&#34;,&#34;价格&#34;:&#34; 10&#34; } {&#34; plan_id&#34;:&#34; 2&#34;,&#34;价格&#34;:&#34; 100&#34; } {&#34; plan_id&#34;:&#34; 3&#34;,&#34;价格&#34;:&#34; 105&#34;但是当我提交一个与plan_id = 1相关的parrticular块时,它在数据库中提交了plan_id = 3,这是最后一个元素的id。
而在数据库中我有两个字段plan_id和price。我需要为每个单独的块在这些字段中插入数据。
请帮助我得到这个。非常感谢。
提前致谢。
请检查错误:
Error: can't assign to properties of (new String("\r\n<pre>Array\n(\n [plan_id] => 3\n [price] => 120\n)\n</pre>")): not an object
fn@http://localhost/ultimate/angular-js/bower_components/angular/angular.min.js line 236 > Function:4:371
hh</<@http://localhost/ultimate/angular-js/bower_components/angular/angular.min.js:293:156
$digest@http://localhost/ultimate/angular-js/bower_components/angular/angular.min.js:144:43
$apply@http://localhost/ultimate/angular-js/bower_components/angular/angular.min.js:147:76
l@http://localhost/ultimate/angular-js/bower_components/angular/angular.min.js:98:419
D@http://localhost/ultimate/angular-js/bower_components/angular/angular.min.js:103:105
ug/</w.onload@http://localhost/ultimate/angular-js/bower_components/angular/angular.min.js:104:77