ui-select 拼音检索报错cannot read property 'tostring' of undefined

在使用ui-select的时候,用拼音检索报错。
这里写图片描述
点进去看文件,错误是出现在过滤器中
这里写图片描述
去看这个过滤器中代码,原因出现在画红框的地方,item[prop]转化为字符串的时候出错
查看item[prop]
过滤器代码

return function(items, props) {
    var out = [];
    if (angular.isArray(items)) {
        items.forEach(function(item) {
            var itemMatches = false;
            var keys = Object.keys(props);
                for (var i = 0; i < keys.length; i++) {
                    var prop = keys[i];
                    var text = props[prop].toLowerCase();
                    if(item[prop].toString().toLowerCase().indexOf(text) !== -1) {
                        itemMatches = true;
                        break;
                    }
                }

                if (itemMatches) {
                    out.push(item);
                }
            });
     } else {
        // Let the output be the input untouched
        out = items;
    }

    return out;
};

过滤器的使用代码

<ui-select-choices repeat="department in departments | propsFilter: {name: $select.search, pingyin: $select.search}">
        <div ng-bind-html="department.name | highlight: $select.search"></div>
    </ui-select-choices>

个人理解:props过滤器的使用是传入一个数组,将输入的拼音转化与data中的拼音匹配从而出结果,当时我的data中拼写的为“pinyin”,而使用中用的“pingyin”

出错点:在data中期待的值为pingyin,而我给出的值为pinyin

如果将data中改为“pinyin”使用中也改为“pinyin”也能解决问题,如下图

这里写图片描述
这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值