角度多选下拉框给出错误元素.多选不是一个函数
Angular multiselectDropdown giving error element.multiselect is not a function
Hi-am在angular js中使用multiselect指令。当我通过angular rout重定向到页面时,它会给我"element.multiselect不是函数"。如果我手动刷新页面,它会正常工作。任何人都不知道如何度过难关。
app.directive('multiselectDropdown', [function() {
return function(scope, element, attributes) {
element = $(element[0]); // Get the element as a jQuery element
// Below setup the dropdown:
element.multiselect({
buttonClass : 'btn btn-small',
buttonWidth : '200px',
buttonContainer : '<div class="btn-group" />',
maxHeight : 200,
enableFiltering : true,
enableCaseInsensitiveFiltering: true,
buttonText : function(options) {
if (options.length == 0) {
return element.data()['placeholder'] + ' <b class="caret"></b>';
} else if (options.length > 1) {
return _.first(options).text
+ ' + ' + (options.length - 1)
+ ' more selected <b class="caret"></b>';
} else {
return _.first(options).text
+ ' <b class="caret"></b>';
}
},
// Replicate the native functionality on the elements so
// that angular can handle the changes for us.
onChange: function (optionElement, checked) {
optionElement.prop('selected'), false;
if (checked) {
optionElement.prop('selected', true);
}
element.change();
}
});
// 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(attributes.ngModel, function () {
element.multiselect('refresh');
});
// Below maybe some additional setup
};
}]);
//my html code
<select name ='escalation_rule_ids' class="multiselect" data-placeholder="Select Escalation"
ng-model="formData.escalation_rule_ids" ng-options="item.id as item.rule_name for item in escalation_list"
multiple="multiple" multiselect-cdropdown
>
</select>
您似乎正在将angular元素覆盖到其他内容中。我会把它换成这个:
app.directive('multiselectDropdown', [function() {
return function(scope, element, attributes) {
var jqueryElement = $(element[0]); // Get the element as a jQuery element
// Below setup the dropdown:
jqueryElement.multiselect({
buttonClass : 'btn btn-small',
buttonWidth : '200px',
buttonContainer : '<div class="btn-group" />',
maxHeight : 200,
enableFiltering : true,
enableCaseInsensitiveFiltering: true,
buttonText : function(options) {
if (options.length == 0) {
return jqueryElement.data()['placeholder'] + ' <b class="caret"></b>';
} else if (options.length > 1) {
return _.first(options).text
+ ' + ' + (options.length - 1)
+ ' more selected <b class="caret"></b>';
} else {
return _.first(options).text
+ ' <b class="caret"></b>';
}
},
// Replicate the native functionality on the elements so
// that angular can handle the changes for us.
onChange: function (optionElement, checked) {
optionElement.prop('selected'), false;
if (checked) {
optionElement.prop('selected', true);
}
jqueryElement.change();
}
});
// Watch for any changes to the length of our select element
scope.$watch(function () {
return element[0].length;
}, function () {
jqueryElement.multiselect('rebuild');
});
// Watch for any changes from outside the directive and refresh
scope.$watch(attributes.ngModel, function () {
jqueryElement.multiselect('refresh');
});
// Below maybe some additional setup
};
相关文章:
- 我可以在json对象中添加一个函数吗
- 如何在JQuery函数中定义一个值,然后调用另一个函数并使用该值
- 是否可以将一个函数输入连接到另一个函数调用的文本
- 在另一个函数中使用变量this
- 在另一个函数成功结束后调用该函数
- mongoose.connect undefined不是一个函数
- 监听器必须是一个函数
- 使用JS函数来使用另一个函数的语法?node.js
- 如何取消object.prototypes javascript的一个函数
- 从Chrome扩展名中的popup.html文件在background.js文件中运行一个函数
- 嵌套到另一个函数中的Fancybox函数;不起作用
- 如何在javascript中使用不止一个函数
- jQuery-在页面加载时执行一个函数
- jquery UI draggable:UI.children不是一个函数
- jQuery Mobile Undefined不是一个函数
- 如何在php中创建一个函数,该函数与文本区域一起工作,通过输入类似[color:red]的内容来打印具有等效颜色的文本
- javascript函数将数据添加到屏幕,但随后被另一个函数覆盖
- JS异常:animate不是一个函数
- 如何将一个函数附加到一个不存在的元素上
- JavaScript/jQuery-添加添加和删除类与下一个函数之间的延迟