Я могу подумать о двух способах использования match
, функции, предназначенной для преобразования упорядоченных значений в позиции индексации:
> sapply(PAIRS, match, LISTN$Names) # returns matrix
Name1 Name2
[1,] 1 2
[2,] 3 4
> as.data.frame(lapply(PAIRS, match, LISTN$Names)) # returns dataframe
Name1 Name2
1 1 2
2 3 4
Если имена не были упорядочены последовательно, вам нужно сначала обратиться к этому. [ 113]
Вы могли передать jqContainer подтвердить/отменить функциям.
Поочередно, назначьте jqContainer свойством вызывающей стороны. Так как подтвердить/отменить функции вызваны как методы вызывающей стороны, у них будет доступ к нему через this
. Но это ограничивает Вас отслеживанием одного диалогового окна на виджет.
Попробуйте что-то вроде этого:
(function() {
var global = this;
/*****************This is new****************/
var jqContainer;
global.confirmationBox = function() {
config = {
container: '<div>',
message:''
}
return {
config: config,
render: function(caller) {
// store the container in the outer objects scope instead!!!!
jqContainer = $(config.container);
jqContainer.append(config.message);
jqContainer.dialog({
buttons: {
'Confirm': caller.confirm_action,
Cancel: caller.cancel_action
}
});
}
}
} //end confirmationBox
global.testWidget = function() {
return {
create_message: function(msg) {
var msg = confirmationBox();
msg.message = msg;
msg.render(this);
},
confirm_action: function() {
//Do approved actions here and close the confirmation box
//Currently not sure how to get the confirmation box at this point
/*******Hopefully, you would have access to jqContainer here now *****/
},
cancel_action: function() {
//Close the confirmation box and register that action was
//cancelled with the widget. Like above, not sure how to get
//the confirmation box back to close it
}
}
}//end testWidget
})();
//Create the widget and pop up a test message
var widget = testWidget();
widget.create_message('You need to confirm this action to continue');
Если это не работает, попытайтесь определить свои обратные вызовы (confirm_action, cancel_action) как члены парламента, не занимающие официального поста Вашего объекта. Но они должны смочь получить доступ к внешнему объему Вашего основного объекта.