我公司的一位开发人员编写了一个Vue.js预先输入组件,在我进入Internet Explorer 11之前,一切似乎都没问题。当输入一个绑定了 searchResults: function(e){
this.isShown = true
this.selectedIndex = 0
this.filterOptions()
if(this.wildcardSearch){
var searchObj = {}
searchObj[this.displayProp] = 'Search For: <strong>'+this.search+'</strong>'
this.matches.unshift(searchObj)
}
// Show first 5 results
this.matches = this.matches.splice(0,5)
},
filterOptions: function(){
var lowSearch = this.search.toLowerCase()
var that = this
if (this.search) // don't filter on empty string
this.matches = this.options.map(function(o){
if (o[that.displayProp].toLowerCase().indexOf(lowSearch) > -1)
return o
}).filter(function(o){return o})
},
函数的输入时,它有时会不接受用户输入的字符。这似乎是我正在使用的代码的性能问题。下面是导致问题的代码,如果我将其全部删除并且什么都不做,则输入没有问题。我可以提出任何性能建议来加快速度吗?
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim numberOfItems = 5
Dim numberOfItemsToRemove = 1
Dim inArray(numberOfItems - 1) As Integer
Dim outArray(numberOfItems - 1 - numberOfItemsToRemove) As Integer
Dim i As Integer
For i = 0 To numberOfItems - 1
While Not Integer.TryParse(InputBox("Enter Number " & i + 1), inArray(i))
MessageBox.Show("Invalid input!")
End While
Next
outArray = inArray.OrderBy(Function(j) j).Skip(numberOfItemsToRemove).ToArray()
MessageBox.Show(
String.Format(
"Input: [{0}], Output: [{1}], average: {2:0.0}",
String.Join(", ", inArray),
String.Join(", ", outArray),
outArray.Average))
End Sub
答案 0 :(得分:0)
使用的map
和filter
都是多余的,特别是因为map
被用作filter
而filter
并没有真正做任何事情。
这个怎么样:
this.matches = this.options.filter(function(o) {
return o[that.displayProp].toLowerCase().indexOf(lowSearch) > -1
})
那就是说,我不明白为什么这会对性能造成影响,但它确实是我看到的唯一问题(如果可以的话,我已将此作为评论)。