简体   繁体   English

Javascript-无法在“MutationObserver”上执行“观察”

[英]Javascript- Failed to execute 'observe' on 'MutationObserver'

I'm trying to create a tic tac toe game in javascript.我正在尝试在 javascript 中创建井字游戏。 I seem to be getting an error saying: Uncaught TypeError: Failed to execute 'observe' on 'MutationObserver': The options object must set at least one of 'attributes', 'characterData', or 'childList' to true..我似乎收到一条错误消息:未捕获的类型错误:无法在“MutationObserver”上执行“观察”:object 选项必须将“属性”、“字符数据”或“子列表”中的至少一个设置为真。

It is on this line:它在这条线上:

  board.positions.forEach((el) => observer.observe(el,config));

It is on the function at the start of the game:游戏开始时在 function 上:

function TicTacToeGame() {
    const board = new Board();
    const humanPlayer = new HumanPlayer(board);
    const computerPlayer = new ComputerPlayer(board);
    let turn = 0;

    this.start = function () {
    const config = {childlist: true};
    const observer = new MutationObserver(()=> takeTurn());
    board.positions.forEach((el) => observer.observe(el,config));
   takeTurn();
    }

I've tried to look up the error but can't find anything similar to it.我试图查找错误,但找不到类似的东西。

Try childList instead of childlist in your config.在您的配置中尝试使用childList而不是childlist

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在“MutationObserver”上执行“观察”:参数 1 不是“节点”类型 - Failed to execute 'observe' on 'MutationObserver': parameter 1 is not of type 'Node' 未捕获的类型错误:无法在“MutationObserver”上执行“观察”:参数 1 的类型不是“节点” - Uncaught TypeError: Failed to execute 'observe' on 'MutationObserver': parameter 1 is not of type 'Node' 无法在“MutationObserver”上执行“观察”:参数 1 不是“节点”类型。 选择2() - Failed to execute 'observe' on 'MutationObserver': parameter 1 is not of type 'Node'. select2() 我收到“未捕获的类型错误:无法在‘MutationObserver’上执行‘观察’:参数 1 不是‘节点’类型。” - I am getting "Uncaught TypeError: Failed to execute 'observe' on 'MutationObserver': parameter 1 is not of type 'Node'." MutationObserver 只观察一次 - MutationObserver observe only once MutationObserver无法观察textarea - MutationObserver fails to observe textarea MutationObserver观察jquery追加? - MutationObserver observe jquery append? javascript-将对象数组推入另一个失败 - javascript- pushing an array of object into another failed “MutationObserver”上的“观察”:参数 1 不是“节点”类型 - 'observe' on 'MutationObserver': parameter 1 is not of type 'Node' MutationObserver.observe:参数 1 不是 object - MutationObserver.observe: Argument 1 is not an object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM