使用laravel4框架

时间:2016-08-30 11:43:01

标签: mysql laravel-4

我对在AngularJS中使用拼接功能毫无疑问。 实际上我也希望从查看页面中删除该行。数据已从数据库中删除但效果仅在刷新页面后才可见,我不想重新加载页面,我只想删除查看页面中的行而不重新加载页面。请帮助解决这个问题。

  

AngularJS

$scope.deleteFunc = function(deleteId)
          {

            $http.get("http://localhost/crud/public/rectangle_delete_page/"+deleteId)
            .then(function successCallback(response)
            {
              var del_obj = {};
              del_obj.del_id = id;
              $scope.select_rectangle.splice(del_obj);

              console.log('successCallback');
              console.log(response);
              alert("Rectangle with id "+deleteId+", deleted..!");
            },
            function errorCallback(response)
            {
              console.log('errorCallback');
              console.log(response);
            });
          };
  

查看页面

<body ng-app="myApp" ng-controller="myCtrl">
    <div class="container">
        <h2>Rectangle dimension</h2><br/>
        <table><td>
        <div>
            <table border=1>
                <tr><td>Height:</td><td><input type="text" ng-model="lngth"><br/></td></tr>
                <tr><td>Width:</td><td><input type="text" ng-model="brdth"><br/></td></tr>
                <tr><td><input ng-click="insertFunc(lngth,brdth)" type="submit" value="Submit"></td></tr>
            </table>
        </div></td>

        <td>
        <div style="border:1px solid red; margin-top:10px; height:100px; width:100px">
            <div style="height:{{lngtha}}px; width:{{brdtha}}px; max-width:100%; max-height:98%; margin-top:10px; background-color:yellow;"></div>
        </div>
        </td>


        <td>
            <div class="table-responsive">
                <table class="table table-condensed" border=1>
                    <tr>
                        <th>ID</th>
                        <th>Length</th>
                        <th>Breadth</th>
                        <th>Draw Rectangle</th>
                        <th>Done</th>
                        <th>Delete</th>
                    </tr>
                    <tr ng-repeat="x in select_rectangle">
                        <td>{{x.id}}</td>
                        <td>{{x.length}}</td>
                        <td>{{x.breadth}}</td>
                        <td><input ng-click='show = true' type="submit" value="Draw" ng-model="myVar"></td>
                        <td width="100%" height="100%">
                            <div style="border:1px solid red; height:100px; width:100px">
                                <div style="height:{{x.length}}px; width:{{x.breadth}}px; max-width:100%; max-height:100%; background-color:yellow" ng-init='show = false' ng-show='show'/></div>
                            </div>
                        </td>
                        <td><input type="submit" value="Delete" ng-click="deleteFunc(x.id)"></td>
                    </tr>
                </table>
            </div>
        </td>
        </table>
    </div>
  

laravel中的控制器

public function rectangle_delete_function(Request $request)
    {
      $deleteId = $request->id;
      return $rect_delete_query = DB::table('rectangle')->where('id', '=', $deleteId)->delete(); 
    }
  

路线

Route::get('/rectangle_json_page', 'NewController@rectangle_json_function');

Route::get('rectangle_delete_page/{id}', 'NewController@rectangle_delete_function');

1 个答案:

答案 0 :(得分:0)

我自己解决了我的问题。我刚刚像这样更新了AngularJS

  

AngularJS

$scope.insertFunc = function(lngth,brdth) {

        $scope.lngtha = lngth*0.375;
        $scope.brdtha = brdth*0.375;

        $http({
          method  : 'POST',
          url     : 'http://localhost/crud/public/insert_rectangle_dimension_page',
          data    : {lngth:$scope.lngth, brdth:$scope.brdth}
         })
        .then(function successCallback(response)
        {
            var obj = {};
            obj.length = lngth;
            obj.breadth = brdth;
            $scope.select_rectangle.unshift(obj);
            console.log(successCallback);
            console.log(response);

        },

        function errorCallback(response)
        {
            console.log('errorCallback');
            console.log(response);
        });
        }

但我遇到了麻烦,我对此并不完全满意,我想从DataBase中获取数据并显示在 VIEW Page 上,目前它是直接插入,而不是从DataBase中获取。请帮忙从DataBase中获取。