答案 0 :(得分:0)
arrayFirst 的最后一个参数 - 是将分配给谓词范围的上下文:
var array = ko.observableArray([1,2,3]);
var context = "Hello";
var result = ko.utils.arrayFirst(array(), function(item) {
// 'this' is equal 'context'
console.log(this);
return item === 2;
}, context);
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.2/knockout-min.js"></script>