Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript VueJs中数据对象的匹配值_Javascript_Vue.js - Fatal编程技术网

Javascript VueJs中数据对象的匹配值

Javascript VueJs中数据对象的匹配值,javascript,vue.js,Javascript,Vue.js,如何从Vue中的数据对象检索数据 我有以下格式的数据: datasets: [{ text:"Cars", value: "[1,2,3]" }, { text:"Trains", value: "[1,4,10] } ] 现在,我从路线道具获得以下信息: this.selectedText= this.$route.name; 其中,这个.route.name是例如“Cars”。 现在我想使用this.selectedValue从这个数组中获取相应的值: 因此,如果this.se

如何从Vue中的数据对象检索数据

我有以下格式的数据:

datasets: [{
 text:"Cars",
 value: "[1,2,3]" 
},
{
 text:"Trains",
 value: "[1,4,10]
}
]
现在,我从路线道具获得以下信息:

this.selectedText= this.$route.name;
其中,
这个.route.name
例如“Cars”
。 现在我想使用
this.selectedValue
从这个数组中获取相应的值:
因此,如果
this.selectedText=“Cars”
那么
this.selectedValue=[1,2,3]
或者基于此,我想检索给定文本的值。

创建一个方法,并使用此代码查找匹配的文本

function setSelectedValue() {
    let matchingDatSet = this.datasets.find(ele => ele.text == this.selectedText);
    if(matchingDataSet !== undefined) {
        this.selectedValue = matchingDataSet.value;
    }
}