-1

非常に奇妙な Meteor の動作が見られます。単純なイベント フック (フォームから情報を収集し、挿入を実行し、Session 変数を更新する) が実行された後、クライアントは再び起動したように見え、ページ全体が再描画されます。実際、Meteor.startup は、ブラウザー ウィンドウが更新されていない (またはそのようなものではない) にもかかわらず、複数回実行されています。さらに奇妙なのは、非常によく似たアプリを作成したにもかかわらず、この動作がまったく表示されないという事実です。異なるプロジェクト間で大きな違いを検出することはできません。

私たちは Meteor バージョン 0.6.4.1 を使用しており (すべての場合)、autopublish と insecure の両方が削除されています。

プレイリスト.html:

<body>
{{> addSong}}
{{> playlist}}
</body>

<template name="addSong">
<form>
    <fieldset>
        <legend>Add a song to the playlist!</legend>
        <div><input type="text" id="artist" /></div>
        <div><input type="text" id="title" /></div>
        <div><button type="submit" id="insertButton">Insert</button></div>
    </fieldset>
</form>
</template>

<template name="playlist">
<div>Votes left: {{votes}}</div>
<ul>
    {{#each songs}}
        <li>
    {{artist}} - {{title}} - {{score}}
    <button class="voteUp" mongo_id="{{_id}}">Vote up!</button>
    <button class="remove" mongo_id="{{_id}}">X</button>
</li>
    {{/each}}
</ul>
</template>

lib/common.coffee

@Songs = new Meteor.Collection "songs"

Songs.allow
    insert: (userID) ->
            true
    update: (userID) ->
            true
    remove: (userID) ->
            true

client/client.coffee

Meteor.subscribe "songs"

Template.playlist.songs = ->
  Songs.find {},{sort:{"score":-1}}

Template.playlist.votes = -> Session.get("votes")

Template.addSong.events
  'click #insertButton': (event,template) ->
    artist = template.find("#artist").value
    title = template.find("#title").value
    Songs.insert({"artist":artist,"title":title,"score":1})
    votes = Session.get("votes")
    Session.set "votes", votes+3
    return

Template.playlist.events
    'click .voteUp': (event,template) ->
        id = event.target.attributes.mongo_id.value
        Songs.update({_id:id},{$inc:{"score":1}})
    'click .remove': (event,template) ->
        id = event.target.attributes.mongo_id.value
        Songs.remove({_id:id})

Meteor.startup ->
    alert "Starting"
    Session.setDefault "votes", 0

サーバー/server.coffee

Meteor.publish "songs", -> Songs.find({})

奇妙な動作を再現するには、フォームに項目を送信するだけです。これにより、毎回起動がトリガーされます (Chrome と Safari で確認済み)。

4

2 に答える 2