【问题标题】:Data table with bootstrap using angularjs app使用 angularjs 应用程序引导的数据表
【发布时间】:2014-04-07 07:17:32
【问题描述】:

我正在使用带有引导程序的 jquery 数据表,并面临一个我不明白的小问题。 这是我的代码

$scope.LoadTypesView = function() {
                           $http({
                method  : 'POST',
                url     : "servierapi.php",
                data    : SessionId,  // pass in data as strings
                headers : { 'Content-Type': 'application/json' }  // set the headers so angular passing info as form data (not request payload)
            })
                .success(function(data) {

                     if(data.aaData.status=="success") // i get two message error and success and work well
                    {
                               $scope.Type = data.aaData.response;
var oTable = $('#typess').dataTable( {
                                    "sDom": "<'row-fluid'<'span6'T><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
                                    "oTableTools": {
                                        "aButtons": [
                                            "copy",
                                            "print",
                                            {
                                                "sExtends":    "collection",
                                                "sButtonText": 'Save <span class="caret" />',
                                                "aButtons":    [ "csv", "xls", "pdf" ]
                                            }
                                        ]
                                    },
                                    "bProcessing": true,
                                    "sAjaxSource": '$scope.Type'
                                } );
                                $('#types').modal('show');    
                    }   
                });
         };

这是我从服务器接收并分配给 $scope.Type 变量的 json 数组

   {"aaData":{"status":"success","response":[{"UserTypeId":"1","TypeName":"Admin","CreatedOn":"2014-02-24 00:00:00","AssignedUsers":[{"UserId":"7","UserTypeId":"1","UserRegionId":"1","UserDepartmentId":"1","UserDesignationId":"1","CNIC":"xxxxxxxx","FirstName":"Hafiz","LastName":"Haseeb","Dob":"January 1,1970","PhotoName":"","PhotoPath":"","Email":"xxxxxx","EducationLevel":"","MartialStatus":"","City":"","State":"","Country":"","MobileNumber":"","EmergencyNumber":"","AddressOne":"","AddressTwo":"","CreatedOn":"0000-00-00 00:00:00","Salary":""}]}]}}

我还在此链接http://jsonformatter.curiousconcept.com/ 上检查 JSON 数组,并且 json 数组有效。 为什么我收到此错误 数据表警告:无法解析来自服务器的 JSON 数据。这是由 JSON 格式错误引起的。?

【问题讨论】:

    标签: javascript php jquery json twitter-bootstrap


    【解决方案1】:

    您正在使用 "sAjaxSource": '$scope.TypeId' 作为字符串,这是一个变量,您可以像示例代码和一些数据函数及其参数一样使用它

                         "sAjaxSource": $scope.TypeId,
                                        "sAjaxDataProp": "aaData",
                                      'fnServerParams' : function (aoData) {
                                        aoData.push({"name":"SessionId",  "value":Session_Id});
    
                                      }
    

    我希望这将有助于解决您的问题

    【讨论】:

    • 是的@Shoail Yasmin 对,我完全按照你说的那样使用,我的错误解决了,但是我添加的一件事然后你的代码是运行` $.extend($.fn.dataTable.defaults, {'sServerMethod ': 'POST' });` 但我面临另一个问题,我得到了数组,我显示了我的问题和未显示的数据表
    【解决方案2】:
    this.Display_error = false; this.sign_report.value.status = 0;
      this.signOptions = {pagingType: 'full_numbers', paging: true, ordering: false, dom: 'Bflrtip', pageLength: 10,
      processing: true, serverSide: true, buttons: ['copyHtml5', {extend: 'excelHtml5', text: 'To Excel', title: this.in_header},
      {extend: 'pdfHtml5', text: 'To Pdf', title: this.in_header},
      {extend: 'print', text: 'Direct Print', title: this.in_header}],
      ajax:  (dataTablesParameters: any, callback) => {
        this.http.post<DataTablesResponse>(this.db.CheckIf_url, dataTablesParameters, {}).subscribe(resp => {
          console.log(resp.data); this.signinoutmodel = resp.data;
          callback({
            draw: resp.draw,
            recordsTotal: resp.recordsTotal,
            recordsFiltered: resp.recordsFiltered,
            data: resp.data
          });
        });
    },
    fnServerParams: function(dt) {
      dt.signedfrom = fd.signedfrom;
      dt.signedtill = fd.signedtill;
      dt.status = fd.status;
      dt.sort_event = fd.sort_event;
      dt.signed_in_at = fd.signed_in_at;
      dt.signed_out_at = fd.signed_out_at;
      dt.sort_category = fd.sort_category;
    },
    columns: [{ data: 'tblid' }, { data: 'staff_id' }, { data: 'fullname' }, { data: 'event_name' },
     { data: 'sign_in' }, { data: 'sing_out'}, { data: 'date_signed' } ]
    };
    

    【讨论】:

    • 您可能会考虑添加一些解释性句子,因为这会增加您的答案对其他用户的价值。
    猜你喜欢
    • 2015-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多