简体   繁体   中英

Where does the function map come from?

All. Forgive me I am not good in the AngularJS and AugularJS-UI.

Currently, I am trying to get the typeahead directive work in my page.

Here is the code. Please review it.

Html

<tr ng-repeat="item in DetailsOfCurRecipe">
                <td><div id="scrollable-dropdown-menu"><input name="DrugDetailName" ng-model="item.ProductName" typeahead="address for address in getDrugDetails($viewValue)" /></div><input type="hidden" name="DrugDetailID" value="{{item.ID}}" /><input type="hidden" name="DrugFileID" value="{{item.DrugFileID}}" /></td>
</tr>

JS

$scope.getDrugDetails = function (val) {
        return $http.get('http://localhost:6249/api/DrugDetails/all', {}).then(function (response) {
            return response.data.map(function (item) {
                return item.ProductName;
            });
        });
    };

I just want to know Where does the response.data.map function come from ? Thanks.

It comes from the Array prototype . It is part of standard core JavaScript .

response.data is the object coming from the angular http service, and the map is a native Javascript function. Here is the definition for map function:

The map() method creates a new array with the results of calling a provided function on every element in this array.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM