Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

AngularJS newbie trying to limit a search filter to one very nested array item. Here's a shot of my output:

<div ng-controller="listController">
  <input type="text" ng-model="searchMe" />
  <table class="table">
    <tr>
        <th>Product Name</th>
        <th>Color</th>
        <th>Size</th>
        <th>Features</th>
    </tr>
    <tr ng-repeat="p in prods | filter:searchMe">
        <td>{{p.products.1.ProductName}}</td>
        <td>{{p.products.1.Color}}</td>
        <td>{{p.products.1.Size}}</td>
        <td>
          <ul ng-repeat="feats in p.features">
            <li>{{feats}}</li>
          </ul>
        </td>
    </tr>
  </table>
</div>

Which displays all the items in the list correctly, including the additional features. Now there are at least another dozen items in the products array, including description, price, etc. The issue is if I search something in the box, it searches the entire array. Now I've tried changing the search input to:

<input type="text" ng-model="search.products.1.ProductName" />
<input type="text" ng-model="search.p.products.1.ProductName" />
<input type="text" ng-model="search.ProductName" />

However as soon as I type one character everything disappears. Yes I've also taken the "me" off the search filter (| filter:search). How can I bind the search to a specific item in a nested array? I'll also need to be able to search by features, but I'm hoping by solving this first it'll lead my to the features. Also my content is being pulled in by a json file if that makes a difference. The search features will eventually be checkboxes as well, and not text inputs, but I figure it shouldn't matter, I will still need to target the specific items (name, color, size, etc).

Thoughts/ideas/suggestions?

share|improve this question
 
You may need to write a custom filter to achieve this. –  ranru Oct 31 at 16:00
 
should find plenty of tutorials on various ways to do this –  charlietfl Oct 31 at 16:01
 
I've gone through several but they don't address nested items, at least the ones I've found. Being a newbie writing a custom filter isn't the easiest of tasks. Is there a tutorial you recommend on how to write a custom filter? –  cfox Oct 31 at 17:09

1 Answer

My solution for the time being is restructuring the json file. Maybe when my knowledge of Angular expands I'll be able to revisit.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.