Angular UI Select:在对象属性中使用过滤器时出错。错误:[$ parse:syntax]语法错误:令牌'。'出乎意料

时间:2016-06-25 06:31:33

标签: angularjs angular-ui-select

Plunkr http://plnkr.co/edit/VR4p6n8rbrGZZOCcCrIa?p=preview

我正在使用angular-ui-select插件。

我正在尝试根据城市,州和国家过滤项目。

我绑定下拉列表的数据具有以下结构:

  vm.people = [
{ name: 'Adam',      email: 'adam@email.com',      age: 12, 
   state: {state:"NY", country:{country:"US"}
  }

},
{ name: 'Amalie',    email: 'amalie@email.com',    age: 12 
  , state: {state:"ca", country:{country:"US"}
  }

},
{ name: 'Estefanía', email: 'estefania@email.com', age: 21 
  , state: {state:"al", country:{country:"US"}
  }

},
{ name: 'Adrian',    email: 'adrian@email.com',    age: 21
  , state: {state:"po", country:{country:"US"}
  }

},
{ name: 'Wladimir',  email: 'wladimir@email.com',  age: 30
  , state: {state:"mn", country:{country:"US"}
  }

},
{ name: 'Samantha',  email: 'samantha@email.com',  age: 30
  , state: {state:"na", country:{country:"US"}
  }

},
{ name: 'Nicole',    email: 'nicole@email.com',    age: 43

  , state: {state:"NX", country:{country:"US"}
  }
},
{ name: 'Natasha',   email: 'natasha@email.com',   age: 54
  , state: {state:"NY", country:{country:"US"}
  }

},
{ name: 'Michael',   email: 'michael@email.com',   age: 15
  , state: {state:"NY", country:{country:"US"}
  }

},
{ name: 'Nicolás',   email: 'nicolas@email.com',    age: 43
, state: {state:"NY", country:{country:"US"}
  } 

}

];

我绑定它如下:

<ui-select ng-model="ctrl.person.selected" theme="bootstrap">
            <ui-select-match placeholder="Select or search a person in the list...">{{$select.selected.name}}</ui-select-match>
            <ui-select-choices repeat="item in ctrl.people |  propsFilter: {name: $select.search, state.state: $select.search,state.country.country: $select.search} ">
              <div ng-bind-html="item.name | highlight: $select.search"></div>
              <small ng-bind-html="item.email | highlight: $select.search"></small>
            </ui-select-choices>
          </ui-select>

我收到此错误:

  

错误:[$ parse:syntax]语法错误:令牌'。'出人意料,   期待表达式[ctrl.people |。]第57列的[:]   propsFilter:{name:$ select.search,state.state:   $ select.search,state.country.country:$ select.search}]从   [.state:$ select.search,state.country.country:$ select.search}]。

修改 我可以使用过滤器而不是 propsfilter &amp;来解决此错误。在整个json中搜索。但我不想这样做,因为json中有很多列,我甚至没有向用户显示..

1 个答案:

答案 0 :(得分:0)

您可以在对象的左侧添加动态对象名称

更改

   <ui-select-choices repeat="item in ctrl.people |  propsFilter: {name: $select.search, state.state: $select.search,state.country.country: $select.search} ">

<ui-select-choices repeat="item in ctrl.people |  propsFilter: {name: $select.search, state: $select.search,country: $select.search}