不知道什么错误,求大神指点

cc.Class({
extends: cc.Component,

properties: {
    leaf: 0,
    leaf_numDispaly: {
        default: null,
        type: cc.Label
    },
    jade: 0,
    cash: 0,
    can_pick_laf: 0
},

get_user_info: function(){
    var url = "http://120.79.68.250/get_user_info/?secret_key=3ff282c272165a33497f4a4c2c69";
    var xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function () {
        if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status < 400)) {
            var response = JSON.parse(xhr.responseText);
            // this.user_info_callback(response);
            var data = response.data;
            console.log("aaaa", data.leaf);
            this.leaf = data.leaf;
            console.log("bbbbb",this.leaf);
            this.jade = data.jade;
            this.cash = data.cash;
            this.leaf_numDispaly.string = 20;
        }
    };
    xhr.open("GET", url, true);
    xhr.send();
},
user_info_callback(response){
    this.leaf_numDispaly.string = response.data.leaf;
},
onLoad: function () {
    this.get_user_info();
    // this.leaf_numDispaly.string = this.leaf;
},

start () {
},

// update (dt) {},

});

执行代码报Uncaught TypeError: Cannot set property ‘string’ of undefined

界面上这个label你设置对了么?

var self = this
var url = “http://120.79.68.250/get_user_info/?secret_key=3ff282c272165a33497f4a4c2c69”;

后面这样
self .leaf_numDispaly.string = 20;

1赞

问题解决了,谢谢。