【发布时间】:2011-03-10 09:34:51
【问题描述】:
我有大量对象“usrSession”,我将它们存储在我的 ArrayCollection usrSessionCollection 中。
我正在寻找一个函数,它返回添加了唯一用户 ID 的最新用户会话。所以是这样的:
1。 搜索 usrSessionCollection,每个 userID 只返回一个 userSessions。
2。 当它返回 x 个 userSessions 然后从 usrSessionCollection 中删除它们
我被卡住了 - 真的很喜欢一些可以帮助我的代码。
function ArrayCollection() {
var myArray = new Array;
return {
empty: function () {
myArray.splice(0, myArray.length);
},
add: function (myElement) {
myArray.push(myElement);
}
}
}
function usrSession(userID, cords, color) {
this.UserID = userID;
this.Cords = cords;
this.Color = color;
}
usrSessionCollection = new ArrayCollection();
$.getJSON(dataurl, function (data) {
for (var x = 0; x < data.length; x++) {
usrSessionCollection.add(new usrSession(data[x].usrID.toString(), data[x].usrcords.toString() ,data[x].color.toString());
}
});
谢谢。
【问题讨论】:
标签: javascript jquery collections queue