múltiples instancias del mismo widget con Durandal
Frecuentes
Visto 331 equipos
1
I have a widget (some kind of profile scope with fields and other stuff). I want to use multiple instances of this widget in one viewmodel as a composition. Is it possible to do such a thing with Durandal and Knockout frameworks?
0 Respuestas
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas javascript knockout.js widget durandal instances or haz tu propia pregunta.
If I understand you correctly then yes, you'd just have an observable array of profile objects in your view model that you'd bind to in your html (using
foreach
o algo). - George HowarthNot exactly. My widget (scopefilter) is a viewmodel with view. It has lots of data, some of which loads from db on widget's activation and stored in ko.observable fields of this widget. And I want to have independent instances of these widgets in some viewmodel (profile editor), those widgets are binded to this editor's view. So how can I have 2 instances of this widgets, while having their data encapsulated and not conflicting? - Seatless
Right, I think Composición es lo que estás buscando. - George Howarth
And also you might want to look at how you construct your widget. You might want to declare it as a constructor so you will have a new instance every time Durandal is requiring it. " ...if you return an object instance, you have created a singleton which will stay in memory for the lifetime of your application. If this is not desired, return a constructor function... " - Razvan
This was actually what I was looking for, but I had figured it out by myself before your answer. Thanks for that anyway :) - Seatless