无法读取未定义的属性(Reading' split'),我想做一些标签选项

发布于 2025-01-21 11:25:06 字数 2207 浏览 1 评论 0原文

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寄与心 2025-01-28 11:25:06

这意味着video.tags存储undefined值。请确保在使用video.tags使用video.tags使用split()方法之前。请参阅下面的代码:

var video = undefined;

// Cannot read properties of undefined (reading 'split')
video.split(',');

检查您的字符串是否为未定义

const video = undefined;

if (typeof video === 'string') {
  const array = video.split(',');
  // Do something ...
} else {
  console.log('video is not a string');
}

// You could also use method chaining.
const r = video?.split(','); 
console.log(r);

This means that video.Tags stores an undefined value. Make sure to check if the video.Tags has a value before using the split() method. See code below:

var video = undefined;

// Cannot read properties of undefined (reading 'split')
video.split(',');

To check whether your string is undefined or not:

const video = undefined;

if (typeof video === 'string') {
  const array = video.split(',');
  // Do something ...
} else {
  console.log('video is not a string');
}

// You could also use method chaining.
const r = video?.split(','); 
console.log(r);

天气好吗我好吗 2025-01-28 11:25:06

您需要学习阅读错误,Elon!

无法读取未定义的属性(阅读'split')

这清楚地说,试图从undefined值访问一个名为split的属性。

现在,您要做的就是检查在抛出错误的代码部分中使用split的位置。

然后,您将了解到,它是tags = video.tags.split(“,”);其中,正在使用,split正在使用。这意味着,tags 视频对象未定义。

现在,您只需要确保标签video> abotive object中始终&amp;它必须是字符串。

You need to learn to read the error, Elon!

Cannot read properties of undefined (reading 'split')

It is clearly saying, a property named split is attempted to be accessed from an undefined 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 in video object is not defined.

Now, you simply need to ensure Tags is present in video object always & it must be a string.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文