1. 程式人生 > >js 批量從快取中讀取資料

js 批量從快取中讀取資料

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="test">取出資料</div>
<script>
    window.onload = function () {
        ////
        let _len = 6;
        let array = [1, 2, 3, 4, 5];
        let cache = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
        ////// 用來處理資料量大的問題(每次從快取中讀取資料) 避免dom節點 渲染過多  每次從快取資料中新增5條資料進行顯示
        var data = ArrRepalce2(array, cache, _len);
        document.getElementById('test').addEventListener('click', function () {
            console.log(data.load());
        });
        /**
         * @param array
         * @param cache
         * @param len
         * @returns {*}
         * @constructor
         */
        function ArrRepalce2(array, cache, len) {
            if (this instanceof ArrRepalce2) {
                if (Array.isArray(array) && Array.isArray(cache)) {
                    this.array = array;
                    this.cache = cache;
                    this.len = len;
                    this.cusour = 0;
                } else {
                    return new TypeError('param error');
                }
            } else {
                return new ArrRepalce2(array, cache, len);
            }
        }

        ArrRepalce2.prototype.load = function () {
            this.array = []; // 預設清空原資訊
            if (this.cusour + this.len > this.cache.length) {
                let first = this.cache.slice(this.cusour, this.cusour + this.len);
                let end = this.cache.slice(0, (this.cusour + this.len) - this.cache.length);
                this.array = first.concat(end);
                this.cusour = (this.cusour + this.len) - this.cache.length;
            } else {
                this.array = this.array.concat(this.cache.slice(this.cusour, this.cusour + this.len));
                this.cusour = this.cusour + this.len;
            }
            return this.array;
        }
    }
</script>
</body>
</html>

相關推薦

js 批量快取讀取資料

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <

python 檔案讀取資料,同時去除掉空格和換行

從檔案中讀取資料,同時去除掉空格和換行,程式碼如下 import numpy as np def sort(path): w = open(path,'r') l = w.readlines() col=[] for k in l: k = k.strip('\n')

Prefuse學習(二)資料庫讀取資料

prefuse是一個非常不錯的開源視覺化專案,尤其是用在social network/complex network上,個人感覺要比jung好。不過可惜的是,prefuse的user manual還在建

怎麼excel讀取資料_python

下載擴充套件庫 xlrd 讀excle xlwt 寫excle 直接在百度上搜就能下載 下載後使用 import xlrd 就可以讀excle檔案了 開啟檔案: xls = xlrd.open_workbook(fileName) 選擇表:括號內為第幾個表 sheet

關於pythonOracle讀取資料中文全是問號的問題

用python連線Oracle資料庫,結果讀取出來的資料,中文部分全是問號,利用: import chardet print(chardet.detect(i)) 發現是ASCII,用了encode和decode來進行轉碼,結果都沒用,最後找到一個帖子,終於將問題解決,只要在程式碼中新增:

spark叢集HDFS讀取資料並計算

一、             利用spark從hadoop的hdfs中讀取資料並計算 1.1準備階段 部署好hadoop分散式搭建(+zookeeper,6臺機器)可以參考這篇部落格:http://blog.csdn.net/vinsuan1993/article/deta

python matplotlib檔案讀取資料繪製散點圖

示例說明:從一個檔案讀取資料,繪製成散點圖 #coding:utf-8 import matplotlib.pyplot as plt import numpy as np import matpl

ffmpeg 記憶體讀取資料(或將資料輸出到記憶體)

原文見雷大神部落格:http://blog.csdn.net/leixiaohua1020/article/details/12980423 更新記錄(2014.7.24): 1.為了使本文更通俗易懂,更新了部分內容,將例子改為從記憶體中開啟。 2.增加了將資料輸出

使用 SqlBulkCopy 批量execl匯入資料

 string text11 = "E:/UserFile/201638114343778799.xls";  //批量從execl中匯入資料               string strConn = "Provider=Microsoft.ACE.OLEDB.12.0

android 將資料儲存到檔案&檔案讀取資料

1.將資料儲存到檔案中,我直接貼程式碼了,基本註釋都在程式碼中,原諒我很懶。 /** * 將資料存到檔案中 * * @param context context

使用RandomAccessFile這個類,檔案讀取資料,卻讀取不出來

請看下面這段程式碼,相關的問題我應經註釋了出來: package timemanager; import java.io.EOFException; import java.io.File; import java.io.FileNotFoundException; im

C# 資料庫讀取資料(ExecuteReader)

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using Syst

python實現檔案讀取資料並繪製成 x y 軸圖形

import matplotlib.pyplot as plt import numpy as np def readfile(filename):     dataList = []     dataNum = 0     with open(filename,'r')

JAVAExcel讀取資料儲存到資料庫

1.jar包 2.資料庫資訊 3.JDBC連線資料庫工具類 package Test; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedSta

快取讀取圖片

上傳頭像圖片時,使用相同的檔名儲存圖片以求覆蓋舊的圖片,當讀取時,由於使用相同的url,瀏覽器就會從快取中讀取圖片,不能實時更新圖片。。。 通過meta指定不儲存cache: <meta http-equiv="pragma" content="no-cache"&

Python--檔案讀取資料

學習python時,發現在使用with open('pi_digits.text') as file_object時,使用相對路徑,總是出現NotFoundFileError的錯誤,後來想到使用絕對路徑。書中提到的在Linux環境中路徑使用的是斜槓(/),在windows環

Kafka系列(四)Kafka消費者:Kafka讀取資料

本系列文章為對《Kafka:The Definitive Guide》的學習整理,希望能夠幫助到大家應用從Kafka中讀取資料需要使用KafkaConsumer訂閱主題,然後接收這些主題的訊息。在我們深入這些API之前,先來看下幾個比較重要的概念。Kafka消費者相關的概念消

20.獲取網路圖片,將圖片儲存在檔案,快取,然後先快取讀取,沒有再檔案讀取

實現的功能主要是標題,那麼接下來我們就分析,如何一步一步的實現這個功能 第一步:建立imgCache資料夾,在裡面建立如下幾個檔案 1.ImgLoaderCallback:用於重新整理ImageView 2.ImageManager:用於管理快取圖片,比如圖片的讀取,還有

txt讀取資料存入二維陣列

在實際應用中,經常需要把txt中的資料讀入到一個數組中,然後再參與運算。在C語言中可以利用fscanf( )函式從檔案中讀取資料, 示例如下: void main() {      double **x,*y;       FILE *fp;       if((fp=fo

python matplotlib檔案讀取資料繪製折線圖

說明:從檔案中讀取資料,繪製直線圖 #coding:utf-8 import matplotlib.pyplot as plt import matplotlib as mpl import num