简体   繁体   English

AngularJS:使用多重选择预先输入Bootstrap

[英]AngularJS : Bootstrap typeahead with multiselect

I am using bootstrap multiselect in my angular application. 我在我的角度应用程序中使用bootstrap multiselect。 (Bootstrap 2.3) (引导程序2.3)

http://davidstutz.github.io/bootstrap-multiselect/index-2-3.html#examples http://davidstutz.github.io/bootstrap-multiselect/index-2-3.html#examples

I want to convert the same thing in to bootstrap typeahead but still the user can multiselect values in search results. 我想将相同的内容转换为提前引导,但用户仍然可以在搜索结果中多选值。

在此处输入图片说明

I am using the highlighter function of bootstrap typeahed to add check-boxes to results. 我正在使用bootstrap typeahed的荧光笔功能将复选框添加到结果中。 I am referring to the this plnkr http://plnkr.co/edit/szO2An1oslDyGftnshyR?p=preview but I am still unable to make my code work. 我指的是这个plnkr http://plnkr.co/edit/szO2An1oslDyGftnshyR?p=preview,但是我仍然无法使我的代码正常工作。

Old Code for multiselect: 多选的旧代码:

  1. to check last selected values 检查最后选择的值

     $scope.selectOptions = function () { var index = fetching the index of checked values; var selectedAttrFound = index>-1; if (selectedAttrFound == true) { angular.element("#attr-value-selector") .multiselect('select', $scope.filterAttributes[index].attributeValues); } }; 
  2. to populate the multiselect 填充多选

     $scope.attrValuesWidget = angular.element("#attr-value-selector") .multiselect({ numberDisplayed: 2, enableFiltering: true, maxHeight: "300", onChange: function (element, checked) { $scope.attributeActionValue = { attribute: $scope.attributeSelected, value: element.val(), checked: checked }; $scope.$apply(); } }) .multiselect('dataprovider', $scope.configAttributeValuesList); 
  3. The Select box 选择框

     <select id='attr-value-selector' multiple='multiple' ></select> 

Although you can easily add checkboxes in your highlighter function.. 尽管您可以轻松地在荧光笔功能中添加复选框。

highlighter: function( item ){
    var bond = bondObjs[ item ];              
    return '<div class="bond">'
            +'<input type="checkbox" class="mightBeRequiredToCollectTheSelectedResult">' 
            +'<img src="' + bond.photo + '" />'
            +'<br/><strong>' + bond.name + '</strong>'
            +'</div>';
}

The problems are; 问题是;

  • typehead.js automatically closes its result after you click one of the search result. 单击搜索结果之一后,typehead.js会自动关闭其结果。 You need to override this first. 您需要先覆盖它。
  • Then you also need to list the selected values into the textfield. 然后,您还需要将选定的值列出到文本字段中。

If you check typehead.js github issues page, issue #254 mentioned that they don't have plan to support multi select, at least for now. 如果您查看typehead.js github问题页面,则问题254提到他们至少暂时没有计划支持多选。

Now I might get downvoted for this, but If I were you I'll consider other alternatives as well. 现在,我可能对此表示不满,但是如果我是您,我也会考虑其他选择。

Hope it helps. 希望能帮助到你。 Cheers. 干杯。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM