2016-02-12 26 views
-1

因此,我使用ASP.NET來編寫後端,當我將100個元素插入數組時,它都可以正常工作,但我有3005個元素可以放入陣列和它會變得更大。ASP.NET/JavaScript:數組索引溢出:實體框架/ LINQ

responseTwo.Append("ts.push('" + busAddrs[final] + "'); "); 

任何人都知道一個辦法讓unlimated指數在JavaScript中的數組?

編輯:在前端,它出來像這樣 -

ts.push('ADDRESS LINE HERE'); ts.push('ANOTHER ADDRESS LINE HERE'); 

ECT ....上述作品如此100,更多的,它停止工作,且錯誤是在這裏:

https://gyazo.com/d7c05e8b57bb348481cd28597f61261c

& &

Uncaught SyntaxError: Unexpected token ILLEGAL

編輯:由於有人投票下來,我打了100次,然後加入ts.push('hello');,它仍然返回相同的錯誤,無論它裏面什麼! - 看我的意見

編輯:ASP後端代碼:

var response = new StringBuilder(); 
    var responseTwo = new StringBuilder(); 
    while (cnt != tbl.Length) 
    { 
     query = busIDs[cnt]; 
     var ttbl = db.tblbus_address.Where(c => c.BusinessID == query).FirstOrDefault(); 
     if(ttbl != null && !string.IsNullOrEmpty(ttbl.Address1)) 
     { 
     busAddrs.Add(ttbl.Address1.ToString()); 
     } else { 
      busAddrs.Add("We do not have an address for this..."); 
     } 
     cnt++; 
    } 

    int final = 0; 
    responseTwo.Append("<script> ts = []; "); 
    while (final != tbl.Length) 
    { 
     response.Append("<li onclick='s(" + final + ");'>" + busNames[final] + "</li>"); 
     responseTwo.Append("ts.push('" + busAddrs[final] + "'); "); 

     final++; 
    } 
    responseTwo.Append(" </script>"); 
    Output.Text = response.ToString(); 
    jsOut.Text = responseTwo.ToString(); 

BusAddr是一個數組,BusName是一個數組,BusIDS是一個數組。

編輯:https://gyazo.com/f95ece23b28579562a145061797b51a4 - 此圖顯示了開發者工具,有沒有「令牌」或任何這樣的,它只是停止工作......

編輯:有是一種以具有在任何特殊字符沒有任何問題數據庫,我搜索了一切。

+1

在JavaScript中的最大數組大小http://stackoverflow.com/questions/6154989/maximum-size-of-an-array-in-javascript。你應該轉義你用來創建'ts.push的字符串.. 。)':'未捕獲的SyntaxError:意外的標記ILLEGAL'它可能包含''' – Hacketo

+0

根據這個,超過100,請看看錯誤和圖像理解,因爲我不認爲它的索引是這個問題。 @Hacketo – KDOT

+0

我只是將4000個元素推送到我的控制檯中的測試數組中,並且它在沒有任何問題的情況下立即運行。我不認爲你的問題與陣列的大小有關,我認爲這是你推動的。 –

回答

0

首先想到

你是串聯的字符串中包含的東西,不能是單引號裏面,像另一個單引號。

因此,在構造字符串之前,必須清除值中的單引號。

是這樣的:

responseTwo.Append( 「ts.push( '」 + busAddrs [最終] .Replace( 「'」, 「\」「); +「');「);

第二個想法

你的腳本標籤中所製作的JavaScript是大約是這樣,並在片段運行在這裏,通過100及以後的打算時,它不會造成錯誤。

我能看到的唯一的事情就是你不會回車,我也是。也許就是這樣?

ts = []; 
 
ts.push('hello'); // 1 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 10 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 20 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 30 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 40 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 50 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 60 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 70 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 80 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 90 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 100 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 
 
ts.push('hello'); // 110 
 
console.log(ts.length);

第三思想

你非法字符是busNames[final]

+0

不是,我循環了100次,然後添加了如下內容:hello,它仍然出現了相同的錯誤。它始終是錯誤的第101個字符串 - 請參閱圖像,字符串 – KDOT

+0

@ KyleE4K中沒有單引號,請將您的完整代碼添加到問題中,如果可以,請使用片段功能。我想玩它。我很無聊;) – toddmo

+0

這是在ASP中,而不是JavaScript @toddmo然而,我的問題是與JavaScript – KDOT

-1

**調試每一件事情之後,我發現我做的陣列中有一個',這導致它搞砸了,但是我在數組的586處遇到了另一個錯誤,其中字符串長度對於數組來說太長了,所以值得n奧丁下來**

的字符串是:水道STREET水道STREET

它造成的錯誤。

https://gyazo.com/4df8807d84f1561df2b35d4bec670b15

我是從「ZBR」按字母順序查詢,所以我把它作爲zbr - 這是T40之前,所以把它轉發,這是一個導致錯誤。

+0

如果這是一個撇號,我會很感激你標記我的答案作爲答案。即使這不是主要問題,這也是問題之一。 – toddmo

+0

撇號不是問題的原因,它是字符串。在我解決了這個問題之後,我得到了錯誤,因爲這是撇號。我遇到的問題與符號無關。 – KDOT