【问题标题】:What is meaning by [Object, Object] error JavaScript[Object, Object] 错误 JavaScript 是什么意思
【发布时间】:2020-03-27 20:39:48
【问题描述】:

我已经调试了将近 2 个小时的代码,并尝试通过使用此站点 Object 来解决它,但它确实有效。控制器模型似乎存在问题。以下是从代码中截取的

    var budgetController = (function () {
    var number = 23;


})();

var UiController = (function () {
    // get the html  input (read the data )
    // you can return whather var by var or retuen one object that has all the HTML compenents 
    var DOMStrings = {
        inputType: '.add__type',
        inputDesc: '.add__description',
        inputValue: '.add__value',
        inputBtn: '.add__btn'
    };

    return {
        getInput: function () {
            return {
                type: document.querySelector(DOMStrings.inputType).value, // Will be either inc or exp
                description: document.querySelector(DOMStrings.inputDesc).value,
                value: document.querySelector(DOMStrings.inputValue).value
            };
        },
        getDOMStrings: function () {
            return DOMStrings;
        }
    };


})();


var Controller = (function (budgetCtr, UICtrl) {
    // Immediately Invoked Function Expression

    var DOM = UICtrl.getDOMStrings();
    var CtrAddItem = function () {
        // pass everthing to here 
        var output = UICtrl.getInput();
        console.info("Data  " + output);

    }
    document.querySelector('.add__btn').addEventListener('click', CtrAddItem);

    document.addEventListener('keypress', function (event) {

        if (event.keyCode === 13 || event.which === 13) {
            CtrAddItem();
        }
    });



})(budgetController, UiController);

每当我在控制器模型上控制台记录输出时,就会出现 [Object , Object]

【问题讨论】:

    标签: javascript html css node.js dom-events


    【解决方案1】:

    每当您使用+ 连接字符串和对象时,都会在对象上调用toString 方法(默认情况下只返回[object Object])。您应该将对象作为第二个参数传递:

    console.info("Data", output);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-08
      • 1970-01-01
      • 1970-01-01
      • 2022-12-14
      • 2021-03-13
      • 1970-01-01
      • 1970-01-01
      • 2017-08-01
      相关资源
      最近更新 更多