我正在尝试学习一些AngularJS。我在本地托管了一个小页面,该页面在MySQL中查找信息。字段是[用户ID,注释,用户名]。
这是网页的代码:
AngularJS测试
<div id="container" ng-app='two_way' ng-controller='two_way_control'>
<input ng-model="name_filter" placeholder="filter names">
<p>{{name_filter}}</p>
<div class="row" ng-repeat="data in profile_pictures | filter:{data.user_Name:name_filter}">
<div class=".col-sm-6 .col-md-5 .col-lg-6" style="background-color:#eee;height:125px;width:500px;margin-left:240px;margin-top:20px;">
<h4 style="padding:10px;">{{data.user_Name}} says:</h4><hr>
<p style="padding:10px;">
{{data.comment}}
</p>
<img src="{{data.profile_picture}}" class="img-circle" style="width:100px;height:100px;margin-left:-140px;margin-top:-130px;">
</div>
</div>
</div>
现在我遇到的问题是关于“ profile_pictures中的数据”的过滤器
我正在尝试仅通过user_Name字段进行过滤。当我在网站的输入框中键入任何内容时,将不会显示任何数据(所有内容都会消失)。我尝试将过滤器硬编码为我知道在数据中的名称,但是当我加载页面时,它只是不显示任何数据。
有任何想法吗?
谢谢您的帮助
最佳答案
筛选器中的语法无效。您需要提供对象的键名作为过滤器对象,不要对对象键@ filter:{data.user_Name:name_filter}"
使用点符号
即尝试
ng-repeat="data in profile_pictures | filter:{user_Name:name_filter}"