根据网址参数过滤“重复”

学习者

我想根据网址中的参数过滤ng-repeat

假设这是网址-

http://sitename/pagename.aspx?Id=27

所以在这里我想过滤ID。喜欢-

ng-repeat="oneItem in listOfItems | filter : 27"

因此,要从URL动态获取数字27

帮我解决这个问题,Lemme知道您是否需要更多信息.. :)

贾洪吉·拉赫莫诺夫(Jahongir Rahmonov)

我认为您没有使用ng-routerui-router

在前端过滤内容是一种不好的做法。相反,您应该将其发送ID到后端并返回正确的结果。然后,您可以简单地执行以下操作:

 ng-repeat="oneItem in listOfItems"

您可以通过更改返回结果然后分配给的方法来执行此操作listOfItems

您可以像这样从网址获取ID:

var url = window.location.href;
$scope.productId = url.split("=")[1]  // this assumes that url is exactly like you wrote

然后,将其添加到您的$httpget请求中,并从后端获取数据。

如果您仍然坚持在前端执行此操作,请执行以下操作:

ng-repeat="oneItem in listOfItems | filter : {id: productId}"  // this assumes that oneItem object has property of id

希望能帮助到你!

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章