无法在字符串上创建属性“类型"-单选按钮过滤器 [英] Cannot create property 'type' on string - radio button filters

查看:102
本文介绍了无法在字符串上创建属性“类型"-单选按钮过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我像这样在Angular中定义单选按钮过滤器:

If I define radio button filters in Angular like so:

<input type="radio" ng-model="filter.type" value="rose"  class="type-filter"> Rose<br>
<input type="radio" ng-model="filter.type" value="tomato"  class="type-filter"> Tomato<br>

显示数据的ng-repeat是:

And the ng-repeat to show the data is:

<div ng-repeat="node in allnodesFiltered | filter:{ plantArray: filter.type}" class="row product-item">
{{node.title}}

过滤效果很好.但是,如果我尝试像这样在过滤器中使用ng-repeat:

The filtering works perfectly. BUT, if I try to use ng-repeat in the filter like this:

<div ng-repeat="plant in plantFilters">
    <input type="radio" ng-model="filter.type" ng-value="filter"  class="type-filter"> Grass
          {{plant}}
    </div> 

我得到了错误:

TypeError: Cannot create property 'type' on string 'rose'
at fn.assign (eval at <anonymous>

这是json数组中一个项目的示例:

Here is an example of an item in the json array:

title: "Euismod Lucidus Oppeto Probo",
body: "Abico adipiscing facilisi nunc singularis sudo. Antehabeo humo     melior neo obruo ulciscor voco. Aliquam commoveo ea mauris nutus os saepius zelus. Brevitas dolus uxor. Ad cogo decet nobis nutus obruo olim turpis venio virtus. Damnum dignissim lobortis meus mos plaga. Eros iriure loquor macto natu paulatim vel. Consequat humo jus nulla. Abico conventio ibidem si tum typicus uxor volutpat. Diam nutus uxor ymo. Abluo caecus imputo loquor lucidus macto nibh obruo usitas.",
Path: "public://product-images/imagefield_THXgQg.jpg",
productType: "Compost, Weedkiller",
plant: "Rose, Tomato"

推荐答案

我设法弄清楚了这一点.在ng-model中,您可以这样引用父对象:

I managed to figure this out. In the ng-model you can refer to the parent like this:

ng-model="$parent.filter.type"

如果有人可以说明它是如何工作的,我会喜欢的.但是,感谢您的输入Akhilesh Jaiswal

I would love it if someone could exaplain how this works. But thanks for the input Akhilesh Jaiswal

这篇关于无法在字符串上创建属性“类型"-单选按钮过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆