小编FrW*_*FrW的帖子

Typescript - TypeError myclass.myFunction不是函数

我遇到以下代码的问题.

它基本上应该做什么.它应该加载和解析给定的JSON文件.在RequestListender中,它应该显示Product.ts中方法返回ID的字符串和字符串.在正确显示的地方,该方法失败并出现下述错误.HelloToString()tProduct.IdtProduct.ToString()

非常感谢提前.

错误信息:

TypeError: tProduct.ToString is not a function. 
 (In 'tProduct.ToString()', 'tProduct.ToString' is undefined)
Run Code Online (Sandbox Code Playgroud)

文件:Test.ts

var currentProduct = null as pvis.Product;

function runTest(path) {
    var request = new XMLHttpRequest();
    request.onload = loadRequestListener;
    request.open("get", path, true);
    request.send();
}

function loadRequestListener () {
    var tProduct : pvis.Product = JSON.parse(this.responseText);
    if (tProduct.Id) {
        currentProduct = tProduct;
        alert('loaded with Id: ' + tProduct.Id );   
        alert('loaded with Content: ' + tProduct.ToString() );  
    }
    else {
        alert('product …
Run Code Online (Sandbox Code Playgroud)

javascript function undefined typescript

25
推荐指数
2
解决办法
3万
查看次数

标签 统计

function ×1

javascript ×1

typescript ×1

undefined ×1