Question

My data looks like:

[
            {
                "_id": "531dbf8b9b9fc50000a8d611",
                "active": true,
                "client": {
                    "_id": "531dbf8b9b9fc50000a8d60e",
                    "name": "TR"
                },
                "company_id": "531dbf8b9b9fc50000a8d60c",
                "createdOn": "2014-03-10T13:35:07.313Z",
                "description": "Gentle Action Application Pads",
                "dimensions": {
                    "weight": 22.4
                },
                "lot": [
                ],
                "meta": {
                    "category": "Face",
                    "msrp": 7.75
                },
                "sku": "11002",
                "unit_of_measure": "each",
                "updatedOn": "2014-03-10T13:35:07.314Z"
            },
            {
                "_id": "531dbf8b9b9fc50000a8d612",
                "active": true,
                "client": {
                    "_id": "531dbf8b9b9fc50000a8d60e",
                    "name": "TR"
                },
                "company_id": "531dbf8b9b9fc50000a8d60c",
                "createdOn": "2014-03-10T13:35:07.317Z",
                "description": "Skin Renewal System - Enriched (CA)",
                "dimensions": {
                    "weight": 22.4
                },
                "lot": [
                ],
                "meta": {
                    "category": "Face",
                    "msrp": 321.6
                },
                "sku": "11700CA",
                "unit_of_measure": "each",
                "updatedOn": "2014-03-10T13:35:07.318Z"
            }
        ]

In my view, I have:

 <input type="text" ng-model="receivingSku" placeholder="Locations loaded via $http" typeahead="sku for sku in getSku($viewValue) | filter:$viewValue" typeahead-on-select="selectedSku()" class="form-control">

I need the sku field for each item to be in the typeahead. How can I accomplish this?

Presently, I get an error: Error: matches is undefined

Was it helpful?

Solution

You can loop over your original array and create an array of just SKU's:

var skus = origArray.map(function(e) {
  return e.sku;
});

The new array can be used for typeahead.

PS - I'm not very familiar with typeahead. If typeahead is capable of peeking into objects, you don't need to do this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top