Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.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 Vue Js过滤器不工作_Javascript_Vue.js_Vuejs2 - Fatal编程技术网

Javascript Vue Js过滤器不工作

Javascript Vue Js过滤器不工作,javascript,vue.js,vuejs2,Javascript,Vue.js,Vuejs2,我正在通过axios实现一个数据集,我试图在VueJs中显示该数据集,以下是数据集: { "model":[ { "id":2, "company_id":5, "salutation":"Mr", "first_name":"Check", "last_name":"Contact", "number":"234567890", "email":"check@contact.

我正在通过
axios
实现一个数据集,我试图在
VueJs
中显示该数据集,以下是数据集:

{
"model":[
    {
        "id":2,
        "company_id":5,
        "salutation":"Mr",
        "first_name":"Check",
        "last_name":"Contact",
        "number":"234567890",
        "email":"check@contact.com",
        "alt_email":null,
        "address":"Thane",
        "city":"Thane",
        "state":"Maharastra",
        "country":"India",
        "profile":"Research-Corporate Access",
        "sectors_interested":"[\"Infrastructure\",\"Financial Services\",\"Capital Goods\",\"Pharmaceuticals\",\"Real Estate\"]",
        "companies_interested":"[{\"value\":7,\"label\":\"Test Company 4\"}]",
        "created_at":"2017-06-02 19:32:30",
        "updated_at":"2017-06-02 19:32:30",
        "deleted_at":null,
        "company":{
            "id":5,
            "name":"Test Company 3",
            "address":"Andheri",
            "city":"Mumbai",
            "state":null,
            "country":"India",
            "type":"Research-Tier II",
            "is_client":0,
            "created_at":"2017-06-02 14:48:20",
            "updated_at":"2017-06-02 14:48:20",
            "deleted_at":null
        }
    },
    {
        "id":3,
        "company_id":4,
        "salutation":"Mr",
        "first_name":"Check 1",
        "last_name":"Contact",
        "number":null,
        "email":"check1@contact.com",
        "alt_email":null,
        "address":null,
        "city":null,
        "state":null,
        "country":null,
        "profile":"Investor-Research Head",
        "sectors_interested":"[\"Economics\",\"Real Estate\",\"Auto\",\"Consumer\",\"Logistics\",\"Oil & Gas\",\"Industrial\",\"Capital Goods\"]",
        "companies_interested":"[{\"value\":7,\"label\":\"Test Company 4\"},{\"value\":8,\"label\":\"Test Company 5\"}]",
        "created_at":"2017-06-03 06:28:03",
        "updated_at":"2017-06-03 06:28:03",
        "deleted_at":null,
        "company":{
            "id":4,
            "name":"Test Company 2",
            "address":"Chennai",
            "city":"Chennai",
            "state":null,
            "country":"India",
            "type":"Investor-Mutual Fund",
            "is_client":0,
            "created_at":"2017-06-02 06:42:16",
            "updated_at":"2017-06-02 15:32:17",
            "deleted_at":null
        }
    },
]
}
基本上,我得到了这个数据集,并试图在其中设置过滤器,我在
data()
中定义了数据集为
model:{}
,我有一个方法为
fetchContactData()
,当我
console.log(this.model)得到响应后,现在将数据设置为
model
我将对象设置为:

但对于筛选,数据集未获得:

我在
computed
属性中有我的过滤器函数

contacts: function() {
    if(this.model)
    {
        return this.model
             .filter(f => (f.company.is_client == 0))
            .map(d => ({label: d.name, value: d.id}))
    }
},
但是这个模型不起作用了,我得到了这个错误

渲染函数出错:“TypeError:this.model.filter不是函数”

当我在if语句之前执行
console.log(this.model)
时,我得到以下结果:

如果我这样做
console.log(this)
我可以看到所需的值被放置在model[


初始化组件时,将模型设置为对象

我在data()中将数据集定义为model:{}

对象没有
过滤器
方法。而是将
模型
初始化为空数组

data(){
    return {
        model: []
    }
}

初始化组件时,将模型设置为对象

我在data()中将数据集定义为model:{}

对象没有
过滤器
方法。而是将
模型
初始化为空数组

data(){
    return {
        model: []
    }
}

如果您改为
console.log(此)
,这是您所期望的吗?@connexo是的,我可以看到模型元素具有所需的值。我已经用响应更新了问题。如果您改为
console.log(此)
相反,这是您所期望的吗?@connexo是的,我可以看到模型元素具有所需的值。我也用回答更新了问题。现在我在观察者“filteredOptions”的getter中得到了
错误:“TypeError:无法读取未定义的属性'toLowerCase'”
filteredOptionswatcher是什么?我没有名字叫
filteredOptions
没有方法,没有watcher。我不知道它从哪里来。可能是我在使用VSelect,从那里来,我把这些过滤选项放在里面。你能来聊天吗?现在我在getter for watcher中发现
错误“filteredOptions”:“TypeError:无法读取未定义的属性'toLowerCase'“
什么是
filteredOptions
观察者?我没有任何
filteredOptions
方法,没有观察者。我不知道它是从哪里来的。可能是我在使用VSelect,从那里来的,我把这些过滤选项放在那里。你能来聊天吗?”?