Question about multiple model instances

33 views
Skip to first unread message

Robert Rackl

unread,
Sep 15, 2013, 1:13:18 PM9/15/13
to spi...@googlegroups.com
Hello there!
I have a question about SpineJS Models

My "TagTextField" is an HTML input Element, that allows the user to input a list of Tags. I already implemented a fancy way for entering new tags. Each Tag is an instance of my TagMdl class. But now I must be possible to show more than one tagtextfield on one page.  How should I organize my TagMdl for that?

Possible Solution:
1)   Let TagMdl now the HTML ID of the input element:

class TagMdl extends Spine.Model
  @configure 'TagMdl', 'tagtextfield_ID', 'tagname'

Advantage: Now I can easily get the list of tags for each tagtextfield
Disadvantage: But now event handling gets impossible. If only one tag is added, I'd have to rerender all tagtextfields on the page.

2)  Create a seperate set of tags for each tagtextfield.
This does not seem to be possible with spine, since a Spine.Model class has its class methods only once.

I am kind of stuck here. Any suggestions?
Yours,
   Robert

Robert Rackl

unread,
Feb 19, 2014, 9:09:09 AM2/19/14
to spi...@googlegroups.com
My problem still exists.  This seems to be a general problem in spine.   How to handle multiple instances of one Model?     I.e. Multiple lists with elements of the same type.

Richard Flosi

unread,
Mar 27, 2014, 12:29:26 PM3/27/14
to spi...@googlegroups.com
Hi Robert,

Yes, in Spine Models are Singletons.

I believe the solution to your problem is to subclass your model and give it a new name, then you will have 2 Singletons.

So if your current model is:
class TagMdl extends Spine.Model
  @configure 'TagMdl', 'tagname'

Create a new module with:
TagMdl = require('path/to/tagmdl')

class TagMdl2 extends TagMdl
  @configure 'TagMdl2', 'tagname'


Reply all
Reply to author
Forward
0 new messages