如何根据nativescript vue中的道具值筛选数组?

如何根据nativescript vue中的道具值筛选数组?,nativescript,nativescript-vue,Nativescript,Nativescript Vue,上周我学习了nativescript vue,作为作业的一部分,我正在sails js上传输一个web应用程序,以制作一个移动应用程序,并在nativescript preview上预览它。我有一个全局变量global.malls,它是app.js中定义的数组,我正在第二个选项卡中基于它创建一个列表视图,如下所示 点击商品,我转到第二页,该页应该列出商场内的商店。使用该方法 onSecondTab:函数(args){ console.log(“带有索引的项:+args.index+“tapp

上周我学习了nativescript vue,作为作业的一部分,我正在sails js上传输一个web应用程序,以制作一个移动应用程序,并在nativescript preview上预览它。我有一个全局变量global.malls,它是app.js中定义的数组,我正在第二个选项卡中基于它创建一个列表视图,如下所示


点击商品,我转到第二页,该页应该列出商场内的商店。使用该方法

onSecondTab:函数(args){
console.log(“带有索引的项:+args.index+“tapped”);
控制台日志(“商场点击:+args.item.Mall”);
这是$navigateTo(MallShop{
转换:{},
道具:{
tappedProduct:args.item
}
});
}
在第二页中,我想列出这些店铺的列表,但我很难根据这个tappedProduct.mall(代表所点击的商城名称)筛选我现有的店铺阵列。我尝试使用computed并创建一个mounted()lifecycle钩子来过滤现有的数组并显示它(在导出默认值内),但都不起作用。优惠券是一个空数组,由我对webapplication的fetch调用填充。shops也是一个空数组,我正在尝试从优惠券中过滤结果


异步装入(){
var response=wait fetch(global.baseUrl+“/shop/json”);
if(response.ok){
this.tups=wait response.json();
log(JSON.stringify(this.coups));
}否则{
console.log(response.statusText);
}
this.shops=this.coups.filter(函数(p){
返回p.mall==“tappedProduct.mall”;
});
},
计算:{
shopsPresent:函数(){
返回此.coups.filter(函数(p){
返回p.mall==“tappedProduct.mall”;
});
}
},

我根据stackoverflow上的一篇类似帖子发现了我做错了什么

这是我的新代码

async mounted() {
        var response = await fetch(global.baseUrl + "/shop/json");

        if (response.ok) {
            this.coupons = await response.json();
            console.log(JSON.stringify(this.coupons));
        } else {
            console.log(response.statusText);
        }

        this.shops = this.coupons.filter(
            function(p) {
                console.log(this.tappedProduct.mall);
                return p.mall == this.tappedProduct.mall;
            }.bind(this)
        );
    },

我从stackoverflow上的一篇类似帖子中发现了我做错了什么

这是我的新代码

async mounted() {
        var response = await fetch(global.baseUrl + "/shop/json");

        if (response.ok) {
            this.coupons = await response.json();
            console.log(JSON.stringify(this.coupons));
        } else {
            console.log(response.statusText);
        }

        this.shops = this.coupons.filter(
            function(p) {
                console.log(this.tappedProduct.mall);
                return p.mall == this.tappedProduct.mall;
            }.bind(this)
        );
    },

您的代码看起来是正确的。试试
ns clean
然后
ns debug android--no-hmr
我试过了。这没用。一位课程伙伴还指出,我应该使用“”而不是“”,因为Javascript双引号将其作为字符串读取,但是当我在第二个选项卡中单击mall时,除了一个空的预览页面之外,我仍然没有得到任何输出。您的代码看起来是正确的。试试
ns clean
然后
ns debug android--no-hmr
我试过了。这没用。一位课程伙伴还指出,我应该使用“”而不是“”,因为Javascript双引号将其作为字符串读取,但是当我单击第二个选项卡中的购物中心时,除了一个空的预览页面之外,我仍然没有得到任何输出