tokenInput给页面元素动态传值用onResult示例

var teacherIds = [];
$("#input-teacher").tokenInput("/server/member/course/list.json?courseId=" + courseId,
    {
        theme: "facebook",
        hintText: "请输入主讲教师名称",
        noResultsText: "没有主讲教师",
        searchingText: "搜索中...",
        propertyToSearch: "realName",
        preventDuplicates: true,
        onResult:function (results){
          results.forEach(function (item,index,array){
          item.id = item.memberId;
        });
          return results;
        },
        onAdd: function (item) {  
          teacherIds.push(item.memberId);  
          $('#input-teacher-hidden').val(teacherIds.join(","));  
        }, 
        onDelete: function (item) { 
          teacherIds.splice(teacherIds.indexOf(item.memberId), 1); 
          $('#input-teacher-hidden').val(teacherIds.join(",")); 
        } 
});

发表评论

邮箱地址不会被公开。 必填项已用*标注