Angularjs - 使用Typeahead必须显示2个值

时间:2015-05-07 13:40:07

标签: javascript html angularjs

我正在使用typeahead,我喜欢它来获取更有用的动态数据

 <input required type="text" ng-model="student" 
  placeholder="{{'STUDENT_ID_FIRST_NAME_LAST_NAME' | translate}}" 
  typeahead="student as student.lastName for student in getStudents($viewValue)"
  typeahead-loading="loading" class="form-control">

我提取学生的javascript代码是

$scope.getStudents = function(val) {
    var queryCriteria = {
        q: JSON.stringify([{
            field: 'lastName',
            op: APP_CONSTANTS.SEARCH_OPERATORS.CONTAINS,
            value: val
        }, {
            field: 'firstName',
            op: APP_CONSTANTS.SEARCH_OPERATORS.CONTAINS,
            value: val
        }, {
            field: 'userId',
            op: APP_CONSTANTS.SEARCH_OPERATORS.CONTAINS,
            value: val
        }]),
        joinCondition: APP_CONSTANTS.JOIN_CONDITIONS.OR,
        order: APP_CONSTANTS.SORTING_ORDER.DESCENDING,
        limit: 10,
        orderBy: 'createdAt',
        page: 1
    }
    return Students.query(queryCriteria).then(function(response) {
        return response.data;
    });
};

我希望显示student.lastNamestudent.firstName的串联。请建议怎么做

1 个答案:

答案 0 :(得分:2)

您可以使用字符串连接student.lastName + ' ' + student.firstName

<input required type="text" ng-model="student" 
placeholder="{{'STUDENT_ID_FIRST_NAME_LAST_NAME' | translate}}" 
typeahead="student as student.lastName+' '+student.firstName for student in getStudents($viewValue)" 
typeahead-loading="loading" class="form-control">