2016-11-04 51 views
0

我想用服務器端Javascript來過濾XPage中的數組。不幸的是我得到以下錯誤:在服務器端JavaScript中使用Array.filter函數

Error calling method 'filter(Function)' on an object of type 'Array [JavaScript Object]'

我有一個字符串像["elem1","elem2","elem3"]

數組我這樣調用該函數:

list.filter(function(){ 

}); 

是否有任何理由爲什麼這個錯誤發生?這個函數是否存在於ssjs中?

這個問題並不重複,因爲Xpages/Lotus Notes在後臺運行Rhino並不清楚。

+1

https://gist.github.com/katio/08bf3f5e058b950cd957 – mplungjan

回答

1

這聽起來像您使用的任何服務器端JavaScript環境不支持ES5功能(這是2009年12月第5版規範中的功能)。

您可以使用填充工具用於添加到陣列說是和其他的東西,看到MDN,但要注意:如果ES5功能不支持,這是不可能的事情添加到Array.prototype沒有使他們可枚舉,這意味着任何代碼(錯)使用for-inloop through arrays將受到影響。

+0

接受爲polyfill爲我做的伎倆。只需將其放入ssjs腳本庫並將其包含到您的頁面中即可。儘管如此,感謝所有其他的意見和建議! – MeMeMax

0

XPage後面有Rhino。而這個SO主題 No Array.filter() in Rhino?說,它已經過時了。不,它不是。幾年前我在某處讀過這些內容。現在看來這不是真的。據丹鐮刀(報價菲利普Riand?)here評論:

It runs on the server jvm and uses javascript as the application language. For licensing reasons, IBM wrote their own jvm javascript engine instead of using Rhino. With Rhino shipping in java 6, they should be able to ship it in Designer 8.5 (or later). The licensing problems may have been around the extensions like @Formulas and type declarations. Classes, modules/namespaces and type declarations are coming in javascript 2 and even google is helping to get that implemented in Rhino. I'd hate to see a non-standard, javascript engine underlying the coolest web development technology in Domino.

Speaking of Rhino, the "most important new feature that is not as certain to be in 8.5 as XPages" uses Rhino and other jvm scripting languages on the client. If this makes it into the product, two years from now most new Notes applications will be written in neither Lotusscript nor Java. I'll leave it at that.

事實上,有一些話題是如何在XPages中使用犀牛,所以用最新版本的Rhino代碼會工作。無論如何,我的建議是使用Java調用。

+0

我沒有發現ssjs默認使用Rhino的證據。我找到[this]這樣的內容(http://dontpanic82.blogspot.co.uk/2010/05/using-rhino-javascript-engine-in-xpages.html)(鏈接自[here](http:/ /stackoverflow.com/questions/26695434/how-to-clean-ssjs-in-domino-server-after-someone-used-javascript-prototype-in​​-a))和[this](https://en.wikipedia .org/wiki/Comparison_of_server-side_JavaScript_solutions),它暗示它沒有。而犀牛的**陣列過濾器** ** **。你能引用一個資料來源嗎? –

相關問題