如何使用淘汰赛 js 映射插件迭代绑定到数据的淘汰赛可观察数组?我创建了这个小提琴来展示我的问题。当我尝试获取淘汰赛 js 数组对象的值时,它会返回一个函数。
有人可以帮我解决这个问题吗?我的代码如下所示。
//Sample JSON Array
var data =
[{"street":"2532 Falkark Dr", "lat":"39.926295", "lng":"-86.012919", "zipcode":"92256"},{"street":"8558 Appleby Ln", "lat":"39.922742", "lng":"-86.017637", "zipcode":"92256"}]
function ViewModel() {
var self = this;
self.addresses = ko.observableArray([]);
ko.mapping.fromJS(data, {}, self.addresses);
}
var viewModel = new ViewModel();
//function binding work order details to view
$(document).ready(function () {
ko.applyBindings(viewModel);
gothroughtheObservableArray(viewModel.addresses());
});
function gothroughtheObservableArray(Addressarray)
{
alert("Got Address Array of length "+Addressarray.length);
for (var i = 0, len = Addressarray.length; i < len; ++i) {
var address = Addressarray[i];
alert(address.street);
}
}