/ / MithrilJS passant des variables à config lors de l'appel m () - jquery, mithril.js

MithrilJS passant des variables à config sur m () call - jquery, mithril.js

J'essaye de faire fonctionner le plugin jQuery FooTable dans mon application mithril. J'ai reçu un appel de configuration comme celui-ci dans mon composant:

view: function(ctrl, args) {
return m("table#globalConfigTable", {config: execFooTable})
}

this.execFooTable = function(element, isInit, context) {
$("#globalConfigTable").footable({
"columns": columns(),
"rows": args.configRows
})
}

args.configRows est ma promesse renvoyée par ma requête GET que je passe à ce composant. Je peux voir qu'il appelle avec succès ma fonction execFooTable, mais je ne parviens pas à trouver comment accéder à ma variable args.configRows. J'ai essayé context.configRows, et un tas d'autres choses, mais elles reviennent toutes comme non définies.

Quelqu'un peut-il m'aider, s'il-vous-plaît? Merci.

Réponses:

2 pour la réponse № 1

Vous pouvez utiliser la fonction ci-dessous:

// Partially apply arguments to a function. Useful for binding
// specific data to an event handler.
// Example use:
//
//   var add = function (x,y) { return x + y; }
//   var add5 = add.papp(5)
//   add5(7) //=> 11
//
Function.prototype.papp = function () {
var slice = Array.prototype.slice,
fn = this,
args = slice.call(arguments);
return function () {
fn.apply(this, args.concat(slice.call(arguments)));
}
}

Ensuite, vous pouvez réécrire votre code comme ceci:

view: function(ctrl, args) {
return m("table#globalConfigTable", {config: execFooTable.papp(args)})
}

this.execFooTable = function(args, element, isInit, context) {
$("#globalConfigTable").footable({
"columns": columns(),
"rows": args.configRows
})
}