Comportamento estranho da tabela inteligente AngularJS com objetos aninhados e pesquisa
Estou tentando implementar o módulo Smart Table no meu aplicativo AngularJS. Eu preferiria isso a alguns outros, principalmente porque os outros pareciam exigir muito código padrão no meu controlador e eu gosto de manter meus controladores o mais SECO possível. Mas estou aberto a outros módulos que podem realizar a mesma coisa sem clichê.
Funciona muito bem ao lidar com uma matriz direta de objetos, mas se alguns desses objetos tiverem objetos aninhados, a filtragem e a classificação terão um comportamento estranho.
Isso vai levar algumas explicações, então tenha paciência comigo.
Primeiro de tudo, aqui está minha matriz de objetos aninhados (abreviada para facilitar a leitura aqui):
$scope.products = [
{
'display': 'Live',
'name': 'LC1D09',
'category': 'Motor Control',
'subcategory': 'Contactor',
'manufacturer': 'Telemecanique',
'specs': {
'phase': 3,
'poles': 3
},
'new': {
'price': 158.95
},
'refurbished': {
'price': 145
},
'onlineStores': {
'amazon': true,
'ebay': false
},
'isCool': true
},
{
'display': 'Pending',
'name': 'FA32020',
'category': 'Circuit Breaker',
'subcategory': 'Molded Case',
'manufacturer': 'Square D',
'specs': {
'phase': 1,
'poles': 2
},
'new': {
'price': 217.79
},
'refurbished': {
'price': 192.82
},
'onlineStores': {
'amazon': true,
'ebay': true
},
'isCool': false
}
];
$scope.displayedProducts = $scope.products;
Aqui está o meu HTML:
<table st-table="displayedProducts" st-safe-src="products" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th st-sort="name">Name</th>
<th st-sort="category">Category</th>
<th>Subcategory</th>
<th>Manufacturer</th>
<th>New Price</th>
<th>Refurb. Price</th>
<th>Display</th>
<th>Specs</th>
<th>Cool</th>
</tr>
<tr>
<th><input st-search="'name'" placeholder="" class="input-sm form-control" type="search"/></th>
<th><input st-search="'category'" placeholder="" class="input-sm form-control" type="search"/></th>
<th><input st-search="'subcategory'" placeholder="" class="input-sm form-control" type="search"/></th>
<th><input st-search="'manufacturer'" placeholder="" class="input-sm form-control" type="search"/></th>
<th><input st-search="new.price" placeholder="" class="input-sm form-control" type="search"/></th>
<th><input st-search="refurbished.price" placeholder="" class="input-sm form-control" type="search"/></th>
<th><input st-search="'display'" placeholder="" class="input-sm form-control" type="search"/></th>
<th><input st-search="'specs'" placeholder="" class="input-sm form-control" type="search"/></th>
<th>
<select st-search="onlineStores.ebay" class="form-control">
<option value=""></option>
<option value="true">Yes</option>
<option value="false">No</option>
</select>
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="product in displayedProducts">
<td>{{product.name}}</td>
<td>{{product.category}}</td>
<td>{{product.subcategory}}</td>
<td>{{product.manufacturer}}</td>
<td>${{product.new.price | number : 0}}</td>
<td>${{product.refurbished.price | number : 0}}</td>
<td>{{product.display}}</td>
<td>{{product.specs}}</td>
<td>{{product.onlineStores.ebay}}</td>
</tr>
</tbody>
</table>
assimisso tudo funciona bem se minha matriz não possui objetos aninhados. Mas com os objetos aninhados (por exemplo,st-search="new.price"
Eu recebo os seguintes problemas (veja a captura de tela):
True
mostrará todos os registros, masFalse
mostrará apenas o registro cujo valor éFalse
.Alguém mais descobriu como lidar com objetos aninhados e o módulo de mesa inteligente?