gpt4 book ai didi

javascript - 访问主干 View 内的自定义属性

转载 作者:行者123 更新时间:2023-12-03 08:44:13 25 4
gpt4 key购买 nike

我有一个主干 View ,想要在其中创建自定义属性并从其他 View 函数访问这些属性。

我有一个属性数据:

data: {
response : JSON.parse($.ajax({
type: 'GET',
url: "dashboard/chart/chart-data",
dataType:"json",
async: false
}).responseText)

},

在初始化函数中我可以访问 this.data:

initialize: function(ob) {
var url = ob.route;
this.render(url);
console.log(this.data)
google.load('visualization', '1', {'callback':this.drawChart, 'packages':['corechart']});
},

哪个记录对象 {response: Object}

但是在另一个函数drawChart中,

console.log(this.data) 给我未定义

和console.log(this)给了我:

Window {top: Window, location: Location, document: document, window: Window, external: Object…}

如何更改drawChart内的范围,以便引用主干 View 对象,而不是窗口元素。

最佳答案

您需要将drawChart绑定(bind)到 View 实例。将 this.drawChart.bind(this) 作为 google.load 选项中的回调传递。

关于javascript - 访问主干 View 内的自定义属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32958515/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com