angularJS ng-repeat过滤器不适用于动态字段

时间:2016-08-02 14:27:05

标签: javascript angularjs angularjs-scope angular-filters

我有一个代码如下:

using System;

public static void Run(string input, out object document, TraceWriter log)
{
    log.Info($"C# manually triggered function called with input: {input}");
    document = new {
        text = $"I'm running in a C# function! {input}"
    };
}

Name 属性为静态时,它可以正常工作。现在我需要过滤动态字段。例如:

<input type="text" ng-model="filteredText">
<ul>
    <li ng-repeat="item in data | filter: {Name : filteredText}">

    </li>
</ul>

在这种情况下, propertyName 是动态的,来自<ul> <li ng-repeat="item in data | filter: {propertyName: filteredText}"> </li> </ul> 。但是这个案例$scope无效。

2 个答案:

答案 0 :(得分:1)

您可以使用以下内容:fiddle

MyModel.transaction
  record = MyModel.lock.find_by(name: update_name) #name is a unique index in the SQL table
  if record
    # The actual manipulation is more complex than something I want to do directly in a SQL statement
    record.update!(value: record.value + add_value)
  else
    record.create(name: update_name, value: add_value)
  end
end

答案 1 :(得分:1)

阅读documentation之后,看起来你必须采取另一种方式。

<input ng-show="propertyFilter == 'Name'" 
       type="text"
       ng-model="filteredText[propertyName]" />

<ul>
    <li ng-repeat="item in data | filter: filteredText">

    </li>
</ul>