GVKun编程网logo

Uncaught TypeError:无法读取未定义的属性“状态或道具”(无法读取未定义的属性是什么问题)

8

在本文中,我们将给您介绍关于UncaughtTypeError:无法读取未定义的属性“状态或道具”的详细内容,并且为您解答无法读取未定义的属性是什么问题的相关问题,此外,我们还将为您提供关于Angul

在本文中,我们将给您介绍关于Uncaught TypeError:无法读取未定义的属性“状态或道具”的详细内容,并且为您解答无法读取未定义的属性是什么问题的相关问题,此外,我们还将为您提供关于Angular 2 Uncaught(in promise):TypeError:无法读取未定义的属性“isActivated”、asp.net – 未捕获TypeError:无法读取未定义的属性“UI”、javascript – dataTables“Uncaught TypeError:无法读取未定义的属性’nTr’”、javascript – Jquery Uncaught TypeError:无法读取未定义的属性’replace’的知识。

本文目录一览:

Uncaught TypeError:无法读取未定义的属性“状态或道具”(无法读取未定义的属性是什么问题)

Uncaught TypeError:无法读取未定义的属性“状态或道具”(无法读取未定义的属性是什么问题)

因此,我开始将应用程序从ES2015转换为使用React的ES6。

我有一个家长班和一个孩子班,

export default class Parent extends Component {    constructor(props) {        super(props);        this.state = {            code: ''''        };    }    setCodeChange(newCode) {        this.setState({code: newCode});    }    login() {        if (this.state.code == "") {            // Some functionality        }    }    render() {        return (            <div>                <Child onCodeChange={this.setCodeChange} onLogin={this.login} />            </div>        );    }}

儿童班

export default class Child extends Component {    constructor(props) {        super(props);    }    handleCodeChange(e) {        this.props.onCodeChange(e.target.value);    }    login() {        this.props.onLogin();    }    render() {        return (            <div>                <input name="code" onChange={this.handleCodeChange.bind(this)}/>            </div>            <button id="login" onClick={this.login.bind(this)}>        );    }}Child.propTypes = {    onCodeChange: React.PropTypes.func,    onLogin: React.PropTypes.func};

但是,这会导致以下错误,

this.state是未定义的

它指的是,

if (this.state.code == "") {    // Some functionality}

知道是什么原因造成的吗?

答案1

小编典典

您可以使用箭头功能来绑定您的功能。您需要在子组件和父组件中都绑定功能。

上级:

export default class Parent extends Component {    constructor(props) {        super(props);        this.state = {            code: ''''        };    }    setCodeChange = (newCode) => {        this.setState({code: newCode});    }    login = () => {        if (this.state.code == "") {            // Some functionality        }    }    render() {        return (            <div>                <Child onCodeChange={this.setCodeChange} onLogin={this.login} />            </div>        );    }}

儿童

export default class Child extends Component {    constructor(props) {        super(props);    }    handleCodeChange = (e) => {        this.props.onCodeChange(e.target.value);    }    login = () => {        this.props.onLogin();    }    render() {        return (            <div>                <input name="code" onChange={this.handleCodeChange}/>            </div>            <button id="login" onClick={this.login}>        );    }}Child.propTypes = {    onCodeChange: React.PropTypes.func,    onLogin: React.PropTypes.func};

还有其他绑定功能的方法,例如您正在使用的一种,但您也需要对父组件进行绑定,例如 <ChildonCodeChange={this.setCodeChange.bind(this)} onLogin={this.login.bind(this)}/>

或者您可以在构造函数中指定绑定为

上级:

constructor(props) {    super(props);    this.state = {        code: ''''    }; this.setCodeChange = this.setCodeChange.bind(this); this.login = this.login.bind(this);}

儿童

constructor(props) {    super(props);    this.handleCodeChange = this.handleCodeChange.bind(this);    this.login = this.login.bind(this);}

Angular 2 Uncaught(in promise):TypeError:无法读取未定义的属性“isActivated”

Angular 2 Uncaught(in promise):TypeError:无法读取未定义的属性“isActivated”

如果我返回到相同的路由路径,它会显示错误

“未保留(承诺):TypeError:无法读取属性’isActivated’未定义”.

但不能在第一时间显示.可以帮我吗

路由

const mainRoutes: Routes = [
    { path: '',pathMatch: 'full',redirectTo: '/home' },{
        path: 'home',loadChildren: './apps/home/home.module#HomeModule',canActivate: [AuthGuard],resolve: {
            crisis: NavigarionResolve
        }
    }
    { path: '**',component: PageNotFoundComponent }
];

零件

import { Component,OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { AuthService }            from '../main/service/auth.service';

@Component({
  selector: 'home-app',templateUrl: 'apps/home/view/home.component.html',providers: [AuthService]
})

export class HomeComponent implements OnInit {
  loaded: boolean = false;
  title = 'Customer Management Home';
  slogan = 'Hi ...Home ';
  views: Object[] = [];
  constructor(private _authService: AuthService,private router: Router) {
    this.views = [
      {
        name: "My Account",description: "Edit my account information",icon: "assignment ind"
      },{
        name: "Potential dates",description: "Find your soulmate!",icon: "pets"
      }
    ];

  }
  logout() {
    this._authService.logout().then(() => {
      this.router.navigate(['/login']);
    });
  }

  ngOnInit() {

  }
}

Navigarion

this.router.navigate(['/home']);
对我来说,问题是被加载的应用程序的第二个实例.
这是由“控件”组件中的无效templateUrl造成的.

我把一个微调器组件从app / components / client / spinner.component移动到app / components / shared / spinner.component,但忘了更新templateUrl.
这意味着我的微调器正在使用错误的HTML加载到我的其他组件内.我在module.ts中使用了组件的正确路径,所以它并没有抛出任何构建错误,但是当找不到spinner.component.html时,mvc6返回了默认的索引页面,所以试图从组件内部加载整个应用程序.当我的内容加载后,移除微调器后,该内部应用程序就被删除.

我完全不了解它,但似乎路由器有一些冲突,因为该应用程序从内部重新加载.
在我的情况下,我很幸运地注意到我的应用程序是glitching,所以我在毛刺部分暂停了javascript并扫描html,并注意到有一个< html>标记在我的微调器内.

尝试在app.component类中设置一个断点,看看它是否被打两次,或者在控制台中运行document.getElementsByTagName(“my-app”)(或者你的app.component被调用),如果你有超过1个返回的元素应该能够从那里调试问题.在我的情况下,这只是在微调器显示时才显示出来,所以如果您的组件在您的页面上进行,请尝试打破每个显示/隐藏.

asp.net – 未捕获TypeError:无法读取未定义的属性“UI”

asp.net – 未捕获TypeError:无法读取未定义的属性“UI”

错误在ASP.NET Ajax应用程序中.这是 JQuery UI代码的错误引用的一行:
Sys.Extended.UI.DropDownBehavior

解决方法

解决方案是替换< asp:ScriptManager>使用< ajaxToolkit:ToolkitScriptManager&gt ;.

javascript – dataTables“Uncaught TypeError:无法读取未定义的属性’nTr’”

javascript – dataTables“Uncaught TypeError:无法读取未定义的属性’nTr’”

所以,这是我在使用ajaxForm的表单中提交后回调时的代码:

function UpdateFormFinished(response,statusText,xhr,$form) {

    if (response['bResult'] == true) {

        var sTestType = $("#sTestType").val();
        var sTableId = "";

        for (index in response) {

            if (typeof response[index] !== "function" && index != "bResult" && index != "sResult") {

                aRowIdPieces = index.split("_");
                sChar = aRowIdPieces[1];

                iColumn = $("#" + index).prevUntil(index).length;
                sTableId = $("#" + sTestType + "_" + sChar).parent().parent().attr("id");

                oTable = $("#" + sTableId).dataTable();
                oTable.fnUpdate(response[index],$("#ixDataTable").val(),iColumn);
            }
        }
    }

    alert(response['sResult']);

    $("#dialog_test_details").dialog("close");
}

if之后的第一行从表单本身的隐藏输入中检索一个值.变量“index”的值为“someWord_X”,其中“X”是整数. iColumn存储我想要更新的列/单元格的索引(我知道编号从零开始,这意味着prevUntil返回我想要更新的列/单元格的索引).最后,“ixDataTable”是表单上的另一个隐藏输入并返回一个整数(我已经使用console.log验证了这一点,以输出该值).

所以,从我能看到的一切,我将好的值传递给fnUpdate,但是我收到错误“无法读取未定义的属性’nTr’”.我查看了堆栈跟踪,问题从dataTables(v1.9.4)中的第6188行开始,这是这一行:

_fnGetTdNodes( oSettings,iRow )[iColumn].innerHTML = sdisplay;

堆栈跟踪进行到第4661行,我在这里复制了第4660到4689行:

oData = oSettings.aoData[iRow];
            if ( oData.nTr !== null )
            {
                /* get the TD child nodes - taking into account text etc nodes */
                anTds = [];
                nTd = oData.nTr.firstChild;
                while ( nTd )
                {
                    sNodeName = nTd.nodeName.toLowerCase();
                    if ( sNodeName == 'td' || sNodeName == 'th' )
                    {
                        anTds.push( nTd );
                    }
                    nTd = nTd.nextSibling;
                }

                iCorrector = 0;
                for ( iColumn=0,iColumns=oSettings.aoColumns.length ; iColumn<iColumns ; iColumn++ )
                {
                    if ( oSettings.aoColumns[iColumn].bVisible )
                    {
                        anReturn.push( anTds[iColumn-iCorrector] );
                    }
                    else
                    {
                        anReturn.push( oData._anHidden[iColumn] );
                        iCorrector++;
                    }
                }
            }

任何关于如何解决这个问题的建议都非常感谢并且将会尝试.我已经验证了表ID是正确的,我也尝试将列索引递增1,这些都没有产生积极的影响.我也试过传递:

ixDataTable = sTestType + "_" + sChar;

作为fnUpdate的第二个参数,但它也不喜欢接收要更新的行的id.

提前谢谢你,希望这是一个非常简单的解决方案.

解决方法

由于这个引用的代码似乎已经过时,我有另一个可能的错误修复任何遇到此问题的人.
只要在选项中定义,就会发生此行为:

"pageLength": "30" //bad

代替

"pageLength": 30 //good

DataTables将其内部计数器解释为030,这会导致此错误.

javascript – Jquery Uncaught TypeError:无法读取未定义的属性’replace’

javascript – Jquery Uncaught TypeError:无法读取未定义的属性’replace’

任何人都可以告诉我为什么我收到此错误:

未捕获的TypeError:无法读取未定义的属性’replace’

function checkNewPost(x) {
        var pid = $('#NewPostbody').attr('class');
        if(pid === 'post-t') {
            setTimeout(checkNewPost,PHP echo $p_id; ?>);
        } else {
            $.ajax({
                type: "POST",url: "/html_postReply.PHP",data: "pid="+pid.replace('post-t','')+"&type=1",success: function(html) {
                    if(html) {
                        $('.tekin').append(html);
                        jQuery("span.timeago").timeago();
                        $(".tekin").scrollTop($(".tekin")[0].scrollHeight);
                    }
                    if(!x) {
                        setTimeout(checkNewPost,PHP echo $p_id; ?>);
                    }
               }
            });
        }
    }
    checkNewPost();
最佳答案
我认为这个错误是由两种情况中的一种引起的,基于上面给出的信息:

> $(‘#NewPostBody)在DOM中找不到
> $(‘#NewPostBody)正在被找到但没有class属性.

这可以使用以下方法解决:

var pid = ($('#NewPostBody').length && $('#NewPostBody').attr('class')) 
    ? $('#NewPostBody').attr('class') 
    : "";

三元运算符以及truthy / falsy逻辑应该导致返回的类或空字符串.无论哪种方式,都可以安全地调用pid.replace(‘post-t’,”)而不会导致错误.

我们今天的关于Uncaught TypeError:无法读取未定义的属性“状态或道具”无法读取未定义的属性是什么问题的分享已经告一段落,感谢您的关注,如果您想了解更多关于Angular 2 Uncaught(in promise):TypeError:无法读取未定义的属性“isActivated”、asp.net – 未捕获TypeError:无法读取未定义的属性“UI”、javascript – dataTables“Uncaught TypeError:无法读取未定义的属性’nTr’”、javascript – Jquery Uncaught TypeError:无法读取未定义的属性’replace’的相关信息,请在本站查询。

本文标签: