angular-ui/ui-grid

losing of appScope in the filters (probably due to cellNav)

Open

#4,334 创建于 2015年9月7日

在 GitHub 查看
 (0 评论) (0 反应) (0 负责人)JavaScript (5,395 star) (2,496 fork)batch import
help wantedneeds: analysis

描述

Hello! I've tried to write a filter to map numeric values from JSON into nice string for dropdown editor. The technic i used is the same as in this tutorial: http://brianhann.com/6-ways-to-take-control-of-how-your-ui-grid-data-is-displayed/ , but i didn't store the 'map' inside filter function, and wanted to get it from $scope -- because in real app, it is populated through one more API call.

The problem is, when I do set property using as filter this $scope parameter: cellFilter: 'genderFilter:grid.appScope.genderDropDownOptions', on the click sometimes its not evaluated and is given to filter callback as simple string. The plunkr below illustrates the problem: http://embed.plnkr.co/PKAEaJ/preview

Now, i'm new to JS and i really want to understand two things:

  1. If you open console, you can see the objects which printed from the filter using console.log(map);. Why, even when we don't activate dropdown yet, there is 3x times filter calls (3 JSON items * 3 = 9)?
  2. When you do double-click on the cell with 'gender', you can see in the console that there is one call during which the value is not evaluated and of course gives error grid.appScope.genderDropDownOptions angular.js:12330 TypeError: map.some is not a function The app still works, though, but why is this? Is there an issue or I don't understand something in inner workings of angular/ui.grid lifecycle?

P.S. Why there is cellNav reference in the subject: because if we don't attach it as dependency, there is No 2) question -- but there is still 1).

Thank you for your great work and time!

贡献者指南