Joa*_*oao 5 javascript angularjs smart-table
我正在尝试在我的AngularJS应用程序中实现智能表模块.我比其他人更喜欢这个,主要是因为其他人似乎需要我的控制器中有很多样板代码,我喜欢尽可能地让我的控制器保持干燥.但我对其他可以在没有样板的情况下完成同样事情的模块持开放态度.
它在处理直接的对象数组时效果很好,但如果其中一些对象具有嵌套对象,则过滤和排序会有奇怪的行为.
这将需要一些解释,所以请耐心等待.
首先,这是我的嵌套对象数组(此处为了可读性而缩短):
$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;
Run Code Online (Sandbox Code Playgroud)
这是我的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>
Run Code Online (Sandbox Code Playgroud)
所以如果我的数组没有嵌套对象,这一切都可以正常工作.但是使用嵌套对象(例如,st-search="new.price"我遇到以下问题(请参见屏幕截图):
True将显示所有记录,但False仅显示其值为的记录False.
还有谁知道如何处理嵌套对象和智能表模块?
$scope.displayedProducts = $scope.products;您需要使用集合的副本,因此您应该做的不是直接分配$scope.displayedProducts= $scope.displayedProducts.concat($scope.products);