无法读取未定义的属性(Reading' split'),我想做一些标签选项
<div class="row no-margin video-title">
<h6><i class="fas fa-book"></i> Tags</h6>
</div>
<div class="image">
<ul class="list-unstyled mb-0">
<%
Tags = video.Tags.split(",");
Tags.forEach (function (tag) {
tag = tag.trim(); %>
<li>
<a href="/tag_search/<%= tag %>"><%= tag %></a>
</li>
<% }) %>
</ul>
</div>
我收到此错误:
TypeError:
E:\livestreaming\video_streaming\views\video-page\index.ejs:374
372|
373|
>> 374| <%- include("side-bar") %>
375|
376| </div>
377| </div>
E:\livestreaming\video_streaming\views\video-page\side-bar.ejs:39
37| <div class="image">
38| <ul class="list-unstyled mb-0">
>> 39| <%
40| Tags = video.Tags.split(",");
41| Tags.forEach (function (tag) {
42| tag = tag.trim(); %>
Cannot read properties of undefined (reading 'split')
at eval ("E:\\livestreaming\\video_streaming\\views\\video-page\\side-bar.ejs":47:35)
at side-bar (E:\livestreaming\video_streaming\node_modules\ejs\lib\ejs.js:692:17)
at include (E:\livestreaming\video_streaming\node_modules\ejs\lib\ejs.js:690:39)
at eval ("E:\\livestreaming\\video_streaming\\views\\video-page\\index.ejs":101:17)
at index (E:\livestreaming\video_streaming\node_modules\ejs\lib\ejs.js:692:17)
at tryHandleCache (E:\livestreaming\video_streaming\node_modules\ejs\lib\ejs.js:272:36)
at View.exports.renderFile [as engine] (E:\livestreaming\video_streaming\node_modules\ejs\lib\ejs.js:489:10)
at View.render (E:\livestreaming\video_streaming\node_modules\express\lib\view.js:135:8)
at tryRender (E:\livestreaming\video_streaming\node_modules\express\lib\application.js:640:10)
at Function.render (E:\livestreaming\video_streaming\node_modules\express\lib\application.js:592:3)
<div class="row no-margin video-title">
<h6><i class="fas fa-book"></i> Tags</h6>
</div>
<div class="image">
<ul class="list-unstyled mb-0">
<%
Tags = video.Tags.split(",");
Tags.forEach (function (tag) {
tag = tag.trim(); %>
<li>
<a href="/tag_search/<%= tag %>"><%= tag %></a>
</li>
<% }) %>
</ul>
</div>
and I receive this error:
TypeError:
E:\livestreaming\video_streaming\views\video-page\index.ejs:374
372|
373|
>> 374| <%- include("side-bar") %>
375|
376| </div>
377| </div>
E:\livestreaming\video_streaming\views\video-page\side-bar.ejs:39
37| <div class="image">
38| <ul class="list-unstyled mb-0">
>> 39| <%
40| Tags = video.Tags.split(",");
41| Tags.forEach (function (tag) {
42| tag = tag.trim(); %>
Cannot read properties of undefined (reading 'split')
at eval ("E:\\livestreaming\\video_streaming\\views\\video-page\\side-bar.ejs":47:35)
at side-bar (E:\livestreaming\video_streaming\node_modules\ejs\lib\ejs.js:692:17)
at include (E:\livestreaming\video_streaming\node_modules\ejs\lib\ejs.js:690:39)
at eval ("E:\\livestreaming\\video_streaming\\views\\video-page\\index.ejs":101:17)
at index (E:\livestreaming\video_streaming\node_modules\ejs\lib\ejs.js:692:17)
at tryHandleCache (E:\livestreaming\video_streaming\node_modules\ejs\lib\ejs.js:272:36)
at View.exports.renderFile [as engine] (E:\livestreaming\video_streaming\node_modules\ejs\lib\ejs.js:489:10)
at View.render (E:\livestreaming\video_streaming\node_modules\express\lib\view.js:135:8)
at tryRender (E:\livestreaming\video_streaming\node_modules\express\lib\application.js:640:10)
at Function.render (E:\livestreaming\video_streaming\node_modules\express\lib\application.js:592:3)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这意味着
video.tags
存储undefined
值。请确保在使用video.tags
使用video.tags
使用split()
方法之前。请参阅下面的代码:检查您的字符串是否为
未定义
:This means that
video.Tags
stores anundefined
value. Make sure to check if thevideo.Tags
has a value before using thesplit()
method. See code below:To check whether your string is
undefined
or not:您需要学习阅读错误,Elon!
这清楚地说,试图从
undefined
值访问一个名为split
的属性。现在,您要做的就是检查在抛出错误的代码部分中使用
split
的位置。然后,您将了解到,它是
tags = video.tags.split(“,”);
其中,正在使用,split
正在使用。这意味着,tags
视频
对象未定义。现在,您只需要确保
标签
在video> abotive object中始终&amp;它必须是字符串。
You need to learn to read the error, Elon!
It is clearly saying, a property named
split
is attempted to be accessed from anundefined
value.Now, all you have to do is, to check where you are using
split
in the part of the code that throws the error.Then you will learn that, it is
Tags = video.Tags.split(",");
where,split
is being used. That means,Tags
property invideo
object is not defined.Now, you simply need to ensure
Tags
is present invideo
object always & it must be a string.