具有angularjs中动态字段名称的typeahead

时间:2016-05-06 10:07:54

标签: angularjs angular-ui-bootstrap

我创建了一个预先输入

<input type="text" placeholder="Search" onfocus="this.placeholder=''" onblur="this.placeholder='Search'" ng-model="selected" typeahead="Customer as Customer.name for Customer in typeaheadSrc | filter:$viewValue" />  

以下数据,

$scope.typeaheadSrc = [{
id:1,
name:'data1'
},
{
id:2,
name:'data2'
}];  

上面的代码完全正常,但我想动态传递列名。在上面的代码我给了'Customer.name',我不想硬编码列名。我在范围变量中获得列名,现在我想在此处指定它。我尝试按以下方式执行,但它无法正常工作

$scope.columndata = 'id';  

 <input type="text" placeholder="Search" onfocus="this.placeholder=''" onblur="this.placeholder='Search'" ng-model="selected" typeahead="Customer as Customer.columndata for Customer in typeaheadSrc | filter:$viewValue" />    

而不是名字字段我正在分配columndata,但它不起作用。请告诉我怎么做。

1 个答案:

答案 0 :(得分:0)

您可以尝试:

<input type="text" placeholder="Search" onfocus="this.placeholder=''" onblur="this.placeholder='Search'" ng-model="selected" typeahead="Customer as Customer[{{columndata}}] Customer in typeaheadSrc | filter:$viewValue" />  

此处 columndata 将是范围变量