问题描述
我正在使用Anglarjs TinyMCE编辑器, https://www.tinymce.com/docs/Integrations/angularjs/,在这里,我在工具箱中添加了自定义下拉按钮,当我使用静态值时它可以正常工作,但是我实际上不知道如何在此下拉列表中加载动态数据值.
I am using anglarjs TinyMCE editor, https://www.tinymce.com/docs/integrations/angularjs/, here, I added custom dropdown button in toolbox, and Its working fine when I used static value,but I don't know actually how can I loaded dynamic data value in this dropdownlist.
setup : function ( editor ) {
editor.addButton( 'customDrpdwn', {
text : 'Customers List',
type: 'menubutton',
icon : false,
menu: [
{
text: 'Customer 1',
onclick: function(){
alert("Clicked on Customer 1");
}
},
{
text: 'Customer 2',
onclick: function(){
alert("Clicked on Customer 2");
}
}
]
});
},
};
我尝试在菜单"文本字段中加载动态值,但出现错误.动态加载我的代码后,像这样-
I try myself to load dynamic value in Menu text field, but I'm getting error. After dynamic loading my code like this -
$scope.customerList = ['Customer 1','Customer 2'];
setup : function ( editor ) {
editor.addButton( 'customDrpdwn', {
text : 'Customers List',
type: 'menubutton',
icon : false,
for(var i =0; i< $scope.customerList.length; i++){
menu: [
{
text: $scope.customerList[i],
onclick: function(){
alert("Clicked on Customer 1");
}
}
]
}
});
}
现在,我的问题是,可以在此自定义字段中加载动态数据.如果是这样,那么我该如何动态加载数据?请帮助我.
Now, my question is that, this is possible to load dynamic data in this custom field. If so then how can I load data dynamically? Please help me.
推荐答案
这是执行此操作的一种方法:
here is one way to do this:
$scope.customerList = ['Customer 1','Customer 2'];
// first make all the menu items
var menuItems = [];
$scope.customerList.forEach(function(customer, index){
item = {
'text': customer,
onclick: function(){
alert("Clicked on " + customer);
}
};
menuItems.push(item);
});
$scope.tinymceOptions = {
plugins: 'link image code',
toolbar: 'undo redo | bold italic | alignleft aligncenter alignright | code | customDrpdwn',
setup: function(editor){
editor.addButton( 'customDrpdwn', {
text : 'Customers List',
type: 'menubutton',
icon : false,
menu: menuItems // then just add it here
});
}
};
这篇关于使用AngularJs在自定义TinyMCE编辑器中添加了动态数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!