0

我正在开发一个具有以下设置的 SpineJs 应用程序:帖子(基本上是聊天室),每个帖子中都有多条消息,就像文本消息流,甚至是聊天室流。我在让Spine.List功能正常工作时遇到问题,但我怀疑我做的不是很正确……</p>

我创建了我的控制器和视图的要点:https ://gist.github.com/coolbox/6880967

post.main.coffee

Spine   = require('spine')
$       = Spine.$

# Models
Post       = require('models/post')
Session    = require('models/session')
Message    = require('models/message')

class Show extends Spine.Controller
  className: 'show content-area'

  events:
    'submit form': 'submit'

  elements:
    '.messages' : 'messages'

  constructor: ->
    super
    @html require('views/posts/show')
    @active @change

    @list = new Spine.List
      el: @messages
      template: require('views/messages/message')
      selectFirst: true

    @list.bind 'change', @render

    Post.bind 'refresh', @render
    Message.bind 'create', @change

  render: =>
    return if !@postId
    @post = Post.exists(@postId)

    if @post
      messages = @post.messages
      @list.render(messages)

    @html require('views/posts/show')(@post)

  change: (params) =>
    if params.id != @postId
      @postId = params.id

    if Session.first()
      Post.fetch
        id: @postId

    @render()

  submit: (e) =>
    e.preventDefault()
    message = Message.fromForm(e.target)
    message.save()


class Main extends Spine.Stack
  className: 'main stack'

  controllers:
    show: Show

module.exports = Main

秀生态

<ul class='messages'></ul>

<div class='footer'>
  <form class='new-message'>
    <input type="hidden" name="post_id" value="<%= @id %>">
    <textarea name='body' placeholder='Type your message here…' autofocus='autofocus'></textarea>
    <input type='submit' value='Send'>
  </form>
</div>

消息.jeco

<li class='item'>
  <%= @body %>
</li>

您将能够看到属于 Post 的“消息”作为对象数组包含在 Post 对象中。我的怀疑是因为这些消息不是 Spine 对象,所以它们不能与我的Spine.list. 如果是这样,我最好的选择是什么?

作为提醒,我在控制台中没有收到任何错误,除了nav我拥有的一些其他点点滴滴之外,屏幕上没有任何内容。

任何帮助将非常感激。谢谢。

4

0 回答 0