0
我做了這2個過濾器:Vue.js重用過濾
過濾器1個
Vue.filter('role',function(value,role)
{
if(!role || 0 === role.length)
{
return value;
}
return value.filter(function(item) {
return item.role.RoleName == role
});
});
過濾器2
Vue.filter('company',function(value,company)
{
if(!company || 0 === company.length)
{
return value;
}
return value.filter(function(item) {
return item.department.company.CompanyName == role
});
});
現在我想將它們結合起來。就像這樣:
組合過濾
Vue.filter('employeefilter',function(value,employeeinfo,filteron)
{
if(!employeeinfo || 0 === employeeinfo.length)
{
return value;
}
return value.filter(function(item) {
return item.filteron == employeeinfo
});
});
我把它傳遞給組合過濾器:
v-for="employee in list | employeefilter selectedrole 'role.RoleName'
但不工作,我怎麼能解決這個問題^
編輯
我現在通過它:
v-for="employee in list | employeefilter selectedrole 'item.role.RoleName'| employeefilter selectedcompany item.department.company.CompanyId"
錯誤:
Uncaught TypeError: Cannot read property 'replace' of undefined
由於這是輝煌的(也許有點遠對我來說)。但我明白,我收到一個錯誤,你可以看看我的編輯? – Jamie
@jamie這意味着'filteron'是未定義的。我想你只需要在item.department.company.CompanyId''上面加引號:'v-for =「employee在list | employeefilter selectedrole'item.role.RoleName'| employeefilter selectedcompany'item.department.company.CompanyId' 「' – Jeff