如何添加自定义或扩展剑道可观察数组?JS 小提琴:http: //jsfiddle.net/balarvs/mctyswh2/3/
$(document).ready(function () {
/* var ar = [
{ id: "10" },
{ id: "12" },
{ id: "20" }
]; */
if (![].getById) {
Array.prototype.getById = function (id) {
'use strict';
var arr = Object(this);
var found;
for (var i = 0; i < arr.length; i++) {
var item = arr[i];
if (item.id == id) {
found = item;
}
}
return found;
};
}
var obser=new kendo.data.ObservableArray( [
{ id: "10" },
{ id: "12" },
{ id: "20" }
]);
var bb = obser.getById("20");
if (bb != undefined) console.log(bb.id);
});