'da Önyükleme Çoklu Seçim Düşüşünü nasıl kullanabilirim? AngularJS'de Önyükleme Çok Noktalı Düşüşünü http://davidstutz.github.io/bootstrap-multiselect/ kullanmak istiyorum. Direktife taşınmanın gerekli olduğunu duydum. Ama bence bu oldukça karmaşık & ne yapmam gerektiğini bilmiyorum. Deneyimliyseniz lütfen bana rehberlik edin! Tks.AngularJS
cevap
Çok tekrar kullanılabilen bir kod oluşturmanız gerekmiyorsa, aslında o kadar da karmaşık değildir. aslında sadece normal jQuery veya JS kodunun, sen yönergesi içindedir kez Temelde
angular.module('yourapp', [])
.directive('multiselectDropdown', [function() {
return function(scope, element, attributes) {
element = $(element[0]); // Get the element as a jQuery element
// Below setup the dropdown:
element.multiselect({
option1: 123,
option2: "abcd",
// etc.
})
// Below maybe some additional setup
}
}]);
: İlk adım temel bir direktif yaratmak ve DOM elementi elde etmektir. HTML kodundaki Sonra
:
<select multiselectDropdown >
<option value="1">One</option>
<option value="2">One</option>
<option value="3">One</option>
</select>
Ayrıca DIV ilave özellikleri belirlemek ve direktifin attributes
parametresini kullanarak değerler elde edebilirsiniz.
Sadece bir addon olarak, bu AngularJS'ye geçmek istediğiniz tüm jquery eklentileri için mükemmel bir modeldir. 'MultiselectDropdown' 'multiselect-dropdown' olmuyor mu? –
Aslında, AngularJS'in en son sürümü HTML'de yönergelerin atamasını sağlamanın birçok yolunu destekliyor, bence “çok satırlı düşme”, “multiselectdropdown”, “data-multiselect-dropdown”, “class =” multiselect-dropdown ”(ve muhtemelen daha fazlası) hepsi geçerlidir. "multiselect-dropdown" aslında "multiselectDropdown" dan daha uygun HTML olabilir. –
@Laurent Üzgünüm, ama sonra ne yapacağımı gerçekten bilmiyordum: | –
Projemde kullanacağım bir yönerge. Chrome ve Firefox'ta çalışır. Seçenekleri kendi ihtiyacınıza göre değiştirebilirsiniz. Angularjs v1.3.15 ve önyükleme-multiselect v0.9.6 çalışan direktif
angular.module('yourApp')
.directive('yourDirective', function() {
return {
link: function (scope, element, attrs) {
element.multiselect({
buttonClass: 'btn',
buttonWidth: 'auto',
buttonContainer: '<div class="btn-group" />',
maxHeight: false,
buttonText: function(options) {
if (options.length == 0) {
return 'None selected <b class="caret"></b>';
}
else if (options.length > 3) {
return options.length + ' selected <b class="caret"></b>';
}
else {
var selected = '';
options.each(function() {
selected += $(this).text() + ', ';
});
return selected.substr(0, selected.length -2) + ' <b class="caret"></b>';
}
}
});
// Watch for any changes to the length of our select element
scope.$watch(function() {
return element[0].length;
}, function() {
element.multiselect('rebuild');
});
// Watch for any changes from outside the directive and refresh
scope.$watch(attrs.ngModel, function() {
element.multiselect('refresh');
});
}
};
});
Güncelleme iki parçacıkları: JavaScript, CoffeeScript
Bu özellik benim için harika bir özelliktir.Firefox'da bir şey seçtikten sonra buttonText işlevi çağrıldığında, uzunluk her zaman sıfırdır, dolayısıyla gösterilen metni güncellemez. Düşünceler? –
@LukeOllett Projemde hem Chrome hem de Firefox'ta çalışıyor. HTML dosyasında bazı sorunlar olabileceğini tahmin ediyorum. Seçim etiketinde 'ng-options' kullanıyorum ve' multiple''e izin veriyorum. –
benimki gibi ...
İşte Ethan Wu'nun cevap almak benim. Ben öğede geçersiz kılınabilir olan böcek ve katma birkaç seçenek sabit: <select multi-select includeSelectAllOption="true" enableFiltering="true" enableClickableOptGroups="true" enableCollapsibleOptGroups="true" multiple ng-model="vm.selectedPlants" ng-options="plant.name group by plant.operatingCompanyName for plant in vm.plants"></select>
// AngularJS: 1.5.8
// bootstrap-multiselect: 0.9.13
angular.module('SocoApp')
.directive('multiSelect', function() {
return {
link: function (scope, element, attrs: any) {
var options: any = {
onChange: function (optionElement, checked) {
if (optionElement != null) {
$(optionElement).removeProp('selected');
}
if (checked) {
$(optionElement).prop('selected', 'selected');
}
element.change();
}
};
//attrs are lowercased by Angular, but options must match casing of bootstrap-multiselect
if (attrs.enablehtml) options.enableHTML = JSON.parse(attrs.enablehtml); //default: false
if (attrs.buttonclass) options.buttonClass = attrs.buttonclass; //default: 'btn btn-default'
if (attrs.inheritclass) options.inheritClass = JSON.parse(attrs.inheritclass); //default: false
if (attrs.buttonwidth) options.buttonWidth = attrs.buttonwidth; //default: 'auto'
if (attrs.buttoncontainer) options.buttonContainer = attrs.buttoncontainer; //default: '<div class="btn-group" />'
if (attrs.dropright) options.dropRight = JSON.parse(attrs.dropright); //default: false
if (attrs.dropup) options.dropUp = JSON.parse(attrs.dropup); //default: false
if (attrs.selectedclass) options.selectedClass = attrs.selectedclass; //default: 'active'
if (attrs.maxheight) options.maxHeight = attrs.maxheight; //default: false, // Maximum height of the dropdown menu. If maximum height is exceeded a scrollbar will be displayed.
if (attrs.includeselectalloption) options.includeSelectAllOption = JSON.parse(attrs.includeselectalloption); //default: false
if (attrs.includeselectallifmorethan) options.includeSelectAllIfMoreThan = attrs.includeselectallifmorethan; //default: 0
if (attrs.selectalltext) options.selectAllText = attrs.selectalltext; //default: ' Select all'
if (attrs.selectallvalue) options.selectAllValue = attrs.selectallvalue; //default: 'multiselect-all'
if (attrs.selectallname) options.selectAllName = JSON.parse(attrs.selectallname); //default: false
if (attrs.selectallnumber) options.selectAllNumber = JSON.parse(attrs.selectallnumber); //default: true
if (attrs.selectalljustvisible) options.selectAllJustVisible = JSON.parse(attrs.selectalljustvisible); //default: true
if (attrs.enablefiltering) options.enableFiltering = JSON.parse(attrs.enablefiltering); //default: false
if (attrs.enablecaseinsensitivefiltering) options.enablecaseinsensitivefiltering = JSON.parse(attrs.enableCaseInsensitiveFiltering); //default: false
if (attrs.enablefullvaluefiltering) options.enableFullValueFiltering = JSON.parse(attrs.enablefullvaluefiltering); //default: false
if (attrs.enableclickableoptgroups) options.enableClickableOptGroups = JSON.parse(attrs.enableclickableoptgroups); //default: false
if (attrs.enablecollapsibleoptgroups) options.enableCollapsibleOptGroups = JSON.parse(attrs.enablecollapsibleoptgroups); //default: false
if (attrs.filterplaceholder) options.filterPlaceholder = attrs.filterplaceholder; //default: 'Search'
if (attrs.filterbehavior) options.filterBehavior = attrs.filterbehavior; //default: 'text', // possible options: 'text', 'value', 'both'
if (attrs.includefilterclearbtn) options.includeFilterClearBtn = JSON.parse(attrs.includefilterclearbtn); //default: true
if (attrs.preventinputchangeevent) options.preventInputChangeEvent = JSON.parse(attrs.preventinputchangeevent); //default: false
if (attrs.nonselectedtext) options.nonSelectedText = attrs.nonselectedtext; //default: 'None selected'
if (attrs.nselectedtext) options.nSelectedText = attrs.nselectedtext; //default: 'selected'
if (attrs.allselectedtext) options.allSelectedText = attrs.allselectedtext; //default: 'All selected'
if (attrs.numberdisplayed) options.numberDisplayed = attrs.numberdisplayed; //default: 3
if (attrs.disableifempty) options.disableIfEmpty = JSON.parse(attrs.disableifempty); //default: false
if (attrs.disabledtext) options.disabledText = attrs.disabledtext; //default: ''
if (attrs.delimitertext) options.delimiterText = attrs.delimitertext; //default: ', '
element.multiselect(options);
// Watch for any changes to the length of our select element
scope.$watch(function() {
//debugger;
return element[0].length;
}, function() {
scope.$applyAsync(element.multiselect('rebuild'));
});
// Watch for any changes from outside the directive and refresh
scope.$watch(attrs.ngModel, function() {
element.multiselect('refresh');
});
}
};
});
- 1. nasıl angularjs öğreniyorum angularjs
- 2. angularjs
- 3. AngularJS
- 4. AngularJS
- 5. AngularJS
- 6. AngularJS
- 7. AngularJS
- 8. AngularJS
- 9. AngularJs
- 10. AngularJS,
- 11. AngularJS
- 12. AngularJS
- 13. angularJS
- 14. AngularJS
- 15. Angularjs
- 16. AngularJS
- 17. angularjs
- 18. AngularJS
- 19. angularJS
- 20. AngularJS
- 21. AngularJS
- 22. AngularJs
- 23. angularjs
- 24. AngularJS
- 25. AngularJS
- 26. AngularJS
- 27. AngularJS
- 28. AngularJs
- 29. angularjs:
- 30. AngularJS
Eğer önyükleme çoklu seçim kullanmam gerekir mi, yoksa Select2 kullanabilirim? http://ivaynberg.github.io/select2/ Bu daha önce Yönlü Yönerge olarak sarılmıştır: https://github.com/angular-ui/ui-select2 – vsp
ui-select2 artık kullanımdan kaldırılmıştır. Https://github.com/angular-ui/ui-select adresini kullanın. –