简体   繁体   English

我在下面有此代码,我希望控制台显示文本

[英]I have this code below and I want the console to display the text

I have this code below and I want to use the underscore in order to display the text below... 我在下面有此代码,我想使用下划线以在下面显示文本...

var log = function(contents) {
        if(_.isArray(contents)) {
            _.each(contents, function(e, i, l) {
                log(e);
              $('#result');
                $('#result').append('</br></br>');
            });
        } else {
            $('#result').append(contents);
        }
    };

    var out = [];
    _.each(ty, function(v,k){
    var hold = {};
    hold.o = {
        l: {
        s:{
            t: 'Trying this for first time...'
        }
      }
    };

    out.push(hold);
    });

    Console.log(out.l.s);

I want to display the text 'Trying this for the first time...' 我想显示文本“第一次尝试...”

You can't do out.ls on an array . 您不能在array上执行out.ls out is an array, so in order to print all the text you have to iterate over the array out是一个数组,因此为了打印所有文本,您必须在数组上进行迭代

Replace: 更换:

Console.log(out.l.s);

With: 带有:

_.each(out, function(item) { 
    console.log(item.o.l.s.t)
});

You could just log the array like this: 您可以像这样记录阵列:

console.log(out)

But that will print the entire array structure with all the objects in it, and not just the text 但这将打印出其中包含所有对象的整个数组结构,而不仅仅是文本

语法错误,请尝试console.log(out);

Thank a lot for your answer, but actually, what i want is something similar to what is below: 非常感谢您的回答,但实际上,我想要的是与下面类似的东西:

hold.options (tooltips object) = {
 (property based on the section generated automatically): {
  (properly based on the itemName generated automatically): {
       t: item.Texts,       
    }
  }

暂无
暂无

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

相关问题 我想在提示中按下 Esc 按钮时提醒一个值,但我不知道...(下面的代码) - I want to alert a value when I press the Esc button in prompt, but I have no idea... (code below) 我想在每个按钮单击事件上加载多个图表。 - I want to load multiple charts on every button click event.I have used below google code 我在运行以下代码时遇到问题,我想打印 msg - I have a problem while running the below code, I want to print msg 我必须在jquery中阅读childs div的坐标,我想按x坐标进行排序,我的代码如下 - I have to read Coordinates of childs div in jquery and i want to sort out by x coordinates my code is below 我在下面有这个代码我希望计数器在发送消息后重置为 0 - I have this code below i want the counter to reset to 0 after the message is sent 我想从下面的代码超链接地址 - i want hyperlink address from below code 我想在下面的代码中添加单引号('') - I want to add single quotes in the below code ('') 我想将以下代码解构为预期的甲酸盐 - i want to destructure the below code to expected formate 我想在 javascript 中的控制台中显示匹配的记录 - i want to display the matching records in the console in javascript 我已将此数据读入控制台。 我想在我的网页中显示“ exampleHeader”和“ exampleBody”。 我该怎么办? - I have this data reading into my Console. I want to display the “exampleHeader” and “exampleBody” in my webpage. How would I do so?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM