我现在正在尝试使用 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);
});
在上面的代码中,我定义了成本格式化程序,我只想在列表视图标签上每个销售价格的价格旁边添加一个 $。要渲染列表视图,我使用:
<ListView id="SteamItems" items="{{ deals }}">
<ListView.itemTemplate>
<GridLayout columns="*, *, 50, 50" rows="50, 50, auto, *">
<Image src="{{ thumb }}" row="0" col="0" cssClass="thumb"/>
<Label text="{{ title }}" key="1" row="0" col="1" cssClass="title"/>
<Label text="{{ normalPrice|costFormatter }}" key="2" row="0" col="2" cssClass="normal-price"/>
<Label text="{{ salePrice|costFormatter }}" key="3" row="0" col="3" cssClass="sale-price"/>
</GridLayout>
</ListView.itemTemplate>
</ListView>
我不明白为什么我得到
JS: Cannot find function or filter: costFormatter
对于我的 nativescript 终端中列表视图中的每一行。我究竟做错了什么?