2017-06-29 54 views
0

不能夠選擇的值添加到過濾器angularjs即時得到這個錯誤(錯誤:意外的令牌)通過選擇值做過濾器不工作

內部控制

$scope.search_type_options=[{name:"Name",value:"name"},{name:"Id",value:"id"},{name:"Update By",value:"updated_by"}]; 

$scope.search_val = function() 
{ 
    $scope.fs={$scope.search_type.value:$scope.search_txt}; 
    $scope.filter_dt=$filter('filter')($scope.temp_data,$scope.fs); 
} 

我需要輸出像 {名: 「拉吉」}

內模板

<div class="form-group"> 
    <select name="search_type" ng-model="search_type" ng-options="item as item.name for item in search_type_options"> 
    <option value="">--select search type</option> 
    </select> 
</div> 
<div class="form-group"> 
    <input type="text" ng-model="search_txt" class="form-control" placeholder="Search"> 
</div> 
    <button type="submit" ng-model="search_btn" ng-click="search_val()"class="btn btn-default">Go</button> 
</div> 
+0

在哪條線路?和請分享$ scope.temp_data數據還 –

回答

0

不知道這是否是一個正確的JS語法

$scope.fs={$scope.search_type.value:$scope.search_txt};

通常應該這樣寫

$scope.fs = {}; 
$scope.fs[$scope.search_type.value] = $scope.search_txt;