2016-11-04 52 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),它暗示它没有。而犀牛的**阵列过滤器** ** **。你能引用一个资料来源吗? –

相关问题