gpt4 book ai didi

javascript - 为什么数组的长度没有显示在浏览器中?

转载 作者:行者123 更新时间:2023-11-28 03:02:51 25 4
gpt4 key购买 nike

代码:

initialize: function() {
this.todos = [
{id: 100, text: 'Rich'},
{id: 200, text: 'Dave'}
];
},



activeTodos: function() {
this.todos = this.todos.length(function() {
return this.todos;
});
this.emitChange();
}



<p>Todo's Remaining: {this.activeTodos} </p>




activeItems: function(){
this.context.executeAction(activeToDosAction);
},

解释:

我正在尝试将数组的大小打印到浏览器窗口(这可以在代码中的 <p> 标记中看到)。到目前为止没有任何显示,我无法弄清楚为什么。 activeTodos应该调用 todos 的长度.

如果人们需要,我可以发布更多代码。我正在使用 reactjs,因此在 HTML 中使用 { } 括号

最佳答案

那里有一些奇怪的事情。如果只需要显示this.todos的长度你可以这样做:

<p>Todo's Remaining: {this.todos.length} </p>

关于javascript - 为什么数组的长度没有显示在浏览器中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33960726/

25 4 0
文章推荐: jquery - 如何使用 AngularJS 中的 ng click 获取
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com