我有一个数组,其中包含与另一个数组的差异。整个脚本每60秒刷新一次,并根据先前的状态检查值10的数组是否有任何变化。如果存在,它将显示在数组“差异”中。
if (!isInited) {
ownerNotifyBaseArray = data.map((value) => ({
id: value[1],
owner: value[10]
}));
} else {
const newOwnerNotifyBaseArray = data.map((value) => ({
id: value[1],
owner: value[10]
}));
const differences = _.differenceWith(newOwnerNotifyBaseArray, ownerNotifyBaseArray, _.isEqual)
console.log('ownerNotifyBaseArray', ownerNotifyBaseArray)
console.log('newOwnerNotifyBaseArray', newOwnerNotifyBaseArray)
console.log('differences', differences)
ownerNotifyBaseArray = newOwnerNotifyBaseArray
}
Data-包含所有数据的数组。 我只从中取一些东西。唯一的ID,以及所有者状态的值。 我正在寻找的是在所有者字段包含“是”时打开一个新窗口。新窗口需要在ID字段中包含唯一ID
var myWindow = window.open("", "WarnOwner", "width=400,height=150");
myWindow.document.write("<p>Hey! You have a new warn owner on: TICKET_ID </p>");
新窗口应仅由所有者字段中的“是”触发。
// 小更新,但不确定我是否走上正轨:
Object.defineProperty(differences, "push", {
enumerable: false, // hide from for...in
configurable: false, // prevent further meddling...
writable: false, // see above ^
value: function () {
for (var i = 0, n = this.length, l = arguments.length; i < l; i++, n++) {
myWindow(this, n, this[n] = arguments[i]); // assign/raise your event
}
return n;
}
});
/////////////
var myWindow = window.open("", "WarnOwner", "width=400,height=150");
myWindow.document.write("<p>Hey! You have a new warn owner on: XXXXXXX </p>");
答案 0 :(得分:0)
对我有用:
var found = differences.find(z => z.owner === 'Yes');
if(found) {
newWindow = window.open("", "WarnOwner", "width=600,height=200");
newWindow.document.write('<p>Hey! You have a new warn owner on: <b>'+(found.id)+'</b> for '+(found.company)+'</p>');
newWindow.focus()
//})
ownerNotifyBaseArray = newOwnerNotifyBaseArray
}
ownerNotifyBaseArray = newOwnerNotifyBaseArray
}