múltiples instancias del mismo widget con Durandal

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?

preguntado el 28 de mayo de 14 a las 13:05

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). -

Not 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? -

Right, I think Composición es lo que estás buscando. -

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... " -

This was actually what I was looking for, but I had figured it out by myself before your answer. Thanks for that anyway :) -

0 Respuestas

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.