AngularJs:过滤时如何避免使用字母

时间:2016-06-07 08:53:32

标签: javascript angularjs angularjs-filter

情况:

由于特殊情况,我不得不制作自己的滤镜,而不是使用普通的角度滤镜:

我有四个级别的嵌套对象:程序 - 天 - 大厅 - 演示。 每个大厅都是一个包含相关演示的手风琴。

无论如何,我制作的滤镜工作正常。

除了一件事:现在过滤器是字母大小写。

因此,如果演示文稿名称为' Automation'和用户类型'自动化'它不会出现在结果中。

代码:

现在正在查找用户在演示文稿名称中输入的字符串的简单indexOf:

var accountId = String()
var dataRows = [NSDictionary]()
var grandChilds = [NSDictionary]()
var dataOfGrandChilds = NSMutableDictionary()
override func viewDidLoad() {
    super.viewDidLoad()
    print("loaded hie \(accountId)")
    let request = SFRestAPI.sharedInstance().requestForQuery("SELECT Name,Id FROM Account where parentid='\(self.accountId)'");
    //SFRestAPI.sharedInstance().send(request, delegate: self);
    SFRestAPI.sharedInstance().sendRESTRequest(request, failBlock: {error in print(error)}, completeBlock: { responce in print(responce)
        self.dataRows = responce["records"] as! [NSDictionary]
        var counter = 0;
        for i in self.dataRows
        {
            let requestForGrandChilds = SFRestAPI.sharedInstance().requestForQuery("select Name,Id from Account where parentid='\(i["Id"]!)'")
            SFRestAPI.sharedInstance().sendRESTRequest(requestForGrandChilds,
            failBlock:
            {
                error in print(error)
                print("error block")
            },
            completeBlock:
            {
                responceChild in
                self.grandChilds = responceChild["records"] as! [NSDictionary]
                self.dataOfGrandChilds["\(counter)"] = self.grandChilds
                print(self.dataOfGrandChilds)
                counter += 1
                print("control still in inner competion block")
                dispatch_async(dispatch_get_main_queue(),
                    { () -> Void in
                        print("Control came to main queue")
                        self.tableView.reloadData()
                })
            })   
        }

    })

}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // #warning Incomplete implementation, return the number of rows
    if let countOfRows = dataOfGrandChilds[section]?.count  // to avoid un-wrapping nil value
    {
        return countOfRows
    }
    return 1
}





override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
    return dataRows[section]["Name"] as? String
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("toViewChilds", forIndexPath: indexPath)
    print(indexPath.section)
    print(dataOfGrandChilds["\(indexPath.section)"])
   if let tempData = dataOfGrandChilds["\(indexPath.section)"]
    {
        if(tempData.count != 0 )//to avoid array index out of bound exceptions
        {
            cell.textLabel?.text = tempData[indexPath.row]["Name"] as? String
        }
    }
    return cell
}

问题:

你知道我怎样才能在过滤时避免使用字母大小写?

谢谢!

2 个答案:

答案 0 :(得分:2)

您可以在两个字符串上使用toLowerCase

var index = name.toLowerCase().indexOf($rootScope.filter.name.toLowerCase());

答案 1 :(得分:1)

实现这一目标的一种方法是使用String to upper case转换为大写:

var name    = presentation.name.toUpperCase();
var index   = name.indexOf($rootScope.filter.name.toUpperCase());

另一种方法是使用正则表达式

var name    = presentation.name;
var index = name.match(new RegExp($rootScope.filter.name, "i"));