gpt4 book ai didi

mysql - 从 Angular js和数据库列表中删除项目

转载 作者:行者123 更新时间:2023-11-29 23:40:21 26 4
gpt4 key购买 nike

嗨,我是 Angular JS 的新手。处于学习阶段。我在 json 编码后从数据库中获取了数据。它工作得很成功。我正在使用代码点火器。现在我想同时删除从 Angular js 和 db 获取的列表。但我无法获得任何教程,或者我无法理解这个概念。如果有人能帮助我,那就太好了。

实际上我的逻辑是捕获帖子的 id 并将此 id 传递给 ci Controller ,然后根据 id 发送到模型来删除帖子。并在从数据库删除后再次获取数据,以便得到新的结果。我的逻辑是否正确,或者是否有其他有效的方法来执行相同的任务。我无法将帖子 ID 传递给 ci Controller 并在 ci Controller 处捕获。

app.js

 function PostsCtrlAjax($scope, $http) {
$http({method: 'POST',
url: '<?php echo base_url().'index.php/cms/get_feedback'; ?>'
}).success(function(data) {
$scope.posts = data; // response data
});

$scope.deleteFeed = function (pId) {
//Defining $http service for deleting a list
alert(pId); //passing post id
$http({ method: 'DELETE',
url: '<?php echo base_url().'index.php/cms/del_feedback'; ?>',
data : pId //how can i send this pId to ci controller
}).success(function (data) {
$scope.posts = data; // response data
});
}
}

html

<ul class="list-group">
<li class="list-group-item feed" ng-repeat="post in posts">
<span style="font-weight: bold">{{post.name}}</span>
<span style="font-size: 12px;">{{post.email}}</span>
<span style="font-size: 12px;">{{post.short_date}}</span>
<br>
<span style="font-size: 12px;color: #aaa;">
{{post.message_summary}}
</span>
<span class="glyphicon glyphicon-remove del_feedback" ng-click="deleteFeed(post.id)" style="position:absolute;top: 0%;right: 0%;color: #E13300;font-size: 10px;display: none;cursor: pointer;"></span>
</li>
</ul>

最佳答案

您好,使用查询字符串将 id 发送到 ci Controller 。

Angular js 函数

 function PostsCtrlAjax($scope, $http)
{
$http({method: 'POST', url: '<?php echo base_url().'index.php/cms/get_feedback'; ?>'}).success(function(data)
{
$scope.posts = data; // response data
});


$scope.deleteFeed = function (pId) {
//Defining $http service for deleting a person
// alert(pId);
$http({ method: 'DELETE',
url: '<?php echo base_url().'index.php/cms/del_feedback?id='; ?>' + pId
}).success(function (data)
{

$http({method: 'POST', url: '<?php echo base_url().'index.php/cms/get_feedback'; ?>'}).success(function(data)
{
$scope.posts = data; // response data
});

});
}
}
// feedback cont

HTML

   <div class="panel-body" id="ng-app" ng-app ng-controller="PostsCtrlAjax" style="height: 300px;overflow-y: scroll;">


<ul class="list-group">
<li class="list-group-item feed" ng-repeat="post in posts">

<span style="font-weight: bold">{{post.name}}</span>
<!--<span style="font-size: 12px;">{{post.email}}</span>-->
<span style="font-size: 12px;" class="pull-right">{{post.short_date}}</span>
<br>
<span style="font-size: 12px;color: #aaa;">

{{post.message_summary}}
</span>
<span class="glyphicon glyphicon-remove del_feedback" ng-click="deleteFeed(post.id)" style="position:absolute;top: 0%;right: 0%;color: #E13300;font-size: 10px;cursor: pointer;"></span>
</li>
</ul>
</div>

CI Controller

   public function get_feedback()
{
$feedback = $this->CmsDbmodel->get_feedback();
$feedback_json = json_encode($feedback);
echo $feedback_json;
}


public function del_feedback()
{
$pid = $_GET['id'];
$feedback = $this->CmsDbmodel->del_feedback($pid);
}

CI模型

function  get_feedback()
{
$query = $this->db->get('feedback');
return $query->result();
}

function del_feedback($pid)
{
$this->db->delete('feedback', array('id' => $pid));
}

关于mysql - 从 Angular js和数据库列表中删除项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26189789/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com