Javascript 使用nativescript转换器

Javascript 使用nativescript转换器,javascript,android,nativescript,Javascript,Android,Nativescript,我现在正试图用javascript将我的钩子嵌入nativescript,我有一个非常基本的问题: let costFormatter= { toView(value){ console.log('Got:' + value); return '$' + value; }, toModel(value){ console.log('Got:' + value);

我现在正试图用javascript将我的钩子嵌入nativescript,我有一个非常基本的问题:

    let costFormatter= {
        toView(value){
            console.log('Got:' + value);
            return '$' + value;
        },
        toModel(value){
            console.log('Got:' + value);
            return '$' + value;
        }
    };
    http.getJSON("<My API Call>").then(function (r){
        page.bindingContext = {
            deals: r,
            costFormatter:costFormatter
        };
    }, function (e){
        //// Argument (e) is Error!
        //console.log(e);
    });

对于nativescript终端中列表视图中的每一行。我做错了什么?

看来你在试图创建一个所谓的“管道”

import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
  name: 'costFormatter',
  pure: true
})

export class CostFormatterPipe implements PipeTransform {
  transform(price: string): string {
    return "$ " + price;
  }
}

然后确保将
CostFormatterPipe
添加到要在其中使用它的模块的
声明
数组中。

检查此文档页面上的说明。ListView项目的特殊注意事项在页面下方的2/3处进行了描述。基本上,在应用程序资源中注册转换器函数。希望这对你有帮助。对我来说是的。

我正试着这样做,是的,但没有角度!Nativescript也应该在没有角度的情况下工作,对吗?哦,对不起。我看到那根管子,以为你用的是角形的:)。。当然可以不使用Angular而使用NativeScript。你看过这个转换器的官方文件了吗?
JS: Cannot find function or filter: costFormatter
import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
  name: 'costFormatter',
  pure: true
})

export class CostFormatterPipe implements PipeTransform {
  transform(price: string): string {
    return "$ " + price;
  }
}