在自定义过滤器中我有很多function get_detail_transaction($id){
$query = mysql_query("SELECT a.*, b.*, c.*, d.unit_name AS unit_konversi_name, b.transaction_detail_unit,
j.unit_name AS unit_utama_name, e.*, f.item_type_name, g.*
FROM transactions a
JOIN transaction_details b ON b.transaction_id = a.transaction_id
JOIN items c ON c.item_id = b.item_id
LEFT JOIN units d ON d.unit_id = b.transaction_detail_unit
LEFT JOIN item_harga e ON e.item_id = b.item_id
LEFT JOIN items_types f ON f.item_type_id = c.item_type
LEFT JOIN item_details g ON g.item_id = b.item_id
LEFT JOIN members h ON h.member_id = a.member_id
LEFT JOIN units j ON j.unit_id = c.unit_id
WHERE a.transaction_id = '$id' GROUP BY b.item_id");
return $query;
}
条件,如果我有选择的话,我想避免重复我的代码。
我尝试创建一个功能,但似乎不想工作。是否可以在过滤器内创建一个功能?如果没有,我如何从过滤器调用函数(如果可能)?
我试图像这样声明:
"if
但由于$ scope而收到错误消息。$scope.mySearch = function(mySearch, searchArr, filled)
,但我怎么称呼它? function(mySearch, searchArr, filled)
,收到有关标签mySearch的警告信息。mySearch : function(mySearch, searchArr, filled)
// I TRIED TO INJECT $SCOPE, BUT THE WAY I DID IT WASN'T PROBABLY GOOD :
.filter('searchFilter', function($filter, $scope)
.filter('searchFilter', function($filter)
{
return function(items, mySearch, searchArr)
{
if((mySearch === "") && (searchArr.name !== ''))
{
var firstSearch = $filter('filter')(items, searchArr.name);
var city = $scope.myTestFunc(mySearch.result, searchArr, firstSearch);
return city;
}
// THE FUNCTION I WOULD LIKE TO CALL ABOVE
$scope.myTestFunc = function(mySearch, searchArr, firstSearch)
{
// Do the job
}
};
});
答案 0 :(得分:1)
var my_search = function(mySearch, searchArr, filled){};
//or
function my_search(mySearch, searchArr, filled){}
我更喜欢第一个...将匿名函数存储到变量中。