我正在通过jquery调用调用WCF服务来加载数据。WCF服务返回数据的速度非常快,但淘汰赛正在缓慢地加载该数据。下面是我使用jquery对wcf服务的调用
 function loadData(id) {
        var input =
            {
                Id: id
            };
        $.ajax({
            url: "../Service/Table/TableData",
            type: "PUT",
            contentType: 'application/json',
            processData: false,
            data: JSON.stringify(input),
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert(errorThrown);
            },
            success: function (allData) {
                var mappedData= $.map(allData, function (item) {
                    return new TableData(item);
                });
                self.TableDataList(mappedData);
            }
        });
    }以下是我的看法
<div  style="overflow: hidden;margin-top: 30px;margin-left: 10px;float:left;" >
            <table style="width: 100%" >
                <colgroup>
                    <col   />
                    <col  />
                    <col/>
                </colgroup>
                <thead><tr>
                           <th style="padding: 0px">Id </th>
                           <th style="padding: 0px">Name</th>
                       </tr>
                </thead>
            </table>
            <div style="overflow: auto;height: 490px;">
                <table id ="Table1" class="Hover" style="width: 100%;" >
                    <colgroup>
                        <col   style="width: 20px"/>
                        <col style="width: 80px"/>
                        <col/>
                    </colgroup>
                    <tbody data-bind="foreach: TableDataList">
                        <tr>
                            <td style="padding: 0px;text-align: left" data-bind="text: Id"  ></td>
                            <td style="padding: 0px;" data-bind="text: Name "></td>
                        </tr>   
                    </tbody>
                </table>
            </div>我正在加载大约20000条记录,需要2分钟才能加载页面。如何避免这种情况?
UPDATE1
使用jquery模板会解决这个问题还是需要分页?
UPDATE2
下面是我的TableData类代码
 function TableData (data) {
        this.Id = ko.observable(data.Id);
        this.Name = ko.observable(data.Name);
        this.LastName = ko.observable(data.LastName );
        this.DateOfBirth = ko.observable(data.DateOfBirth );
        this.Age= ko.observable(data.Age);
    }发布于 2013-06-28 09:16:02
分页是最好的解决方案,因为这是@nemesv。在客户端处理20000条记录将有其自身的性能成本,同时在页面上呈现内容,因此它不是执行缓慢的淘汰制框架。因此,您也可以使用按需加载"onScreenscroll“或类似的东西来加快页面速度。
发布于 2013-06-28 10:56:33
我们能看到TableData类的代码吗?我认为您为这个类中的每个属性创建了许多可观察到的值。
由于视图不包含任何输入字段,所以我想您不希望修改数据。
我也是这么认为。TableData类是减慢代码速度的原因。TableData类是无用的,因为它中没有任何计算。而且,由于您不想修改数据,所以不需要TableData属性的可观察性。
试着用这个代替成功的功能。
success: function (allData) {
    self.TableDataList(allData);
}See fiddle
https://stackoverflow.com/questions/17361105
复制相似问题