0

以下に Marionette アプリケーションをリストし、HTML を次に示します。「処理」ボタンを押すとページからフォームが消えるようにしたいと思います。hideForm メソッドでは、クリック イベントでフォームを非表示にしようとしたことがいくつかあります。これらの試みのうち、このコマンド「$('.form').hide()」のみが機能します。問題は、ボタンをクリックするとフォームが消えてすぐに再表示されるという点で、部分的にしか機能しないことです。最終的に私は自分が間違っていることを知りたいのですが、hideform メソッドにある他のメソッドがまったく何もしない理由を誰かに教えてもらえれば、説明が大好きです。

MyApp = new Backbone.Marionette.Application();

MyApp.addRegions({
formBox : '#formBox',
listBox : '#listBox'
});

Entry = Backbone.Model.extend({
defaults: {
    entry : 'Blank'
},
});

EntryList = Backbone.Collection.extend({
model: Entry
});

FormView = Backbone.Marionette.ItemView.extend({
tagName: 'form',
template: '#form-template',
className: 'form',

events:{
    'click #processInput' : 'hideForm'
},

hideForm : function(){
    //$('.form').css('display','none')
    //document.getElementById("form").style.display="none";
    $('.form').hide();
}

});

EntryView = Backbone.Marionette.ItemView.extend({
tagName: 'tr',
template: '#entry-template',
className: 'entry',

events: {
    'click .delete' : 'destroy'
},

destroy : function()
{
    this.model.destroy();
}
});

EntriesView = Backbone.Marionette.CompositeView.extend({
tagName: 'table',
template: '#entries-template',
itemView: EntryView,

appendHtml: function(collectionView, itemView){
    collectionView.$('tbody').append(itemView.el);      
}
});

MyApp.addInitializer(function(test){
    var entriesView = new EntriesView({
    collection: test.entry
    });

    var formView = new FormView();
    MyApp.formBox.show(formView); 
    MyApp.listBox.show(entriesView);
});

$(document).ready(function(){
    var ents = new EntryList([
    new Entry({ entry: 'test a' }),
    new Entry({ entry: 'test b' }),
    new Entry({ entry: 'test c' })
]);

MyApp.start({entry: ents});

});

HTML:

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="assets/screen.css">
        <title>Simple Demo</title>
</head>
<body>
        <div id = "formBox">
        </div>

        <div id = "listBox">
    </div>
    <script type="text/template" id="form-template">
            <input id = "a" placeholder = "a" autofocus>
            <br />
            <input id = "b" placeholder = "b">
            <br />
            <textarea id = "c" placeholder = "c"></textarea>
            <br />
            <button id = "processInput" >process</button>
        </script>
    <script type="text/template" id="entries-template">
            <thead>
                <tr class='header'>
                    <th>Entry</th>
                </tr>
            </thead>
            <tbody>
            </tbody>
        </script>
        <script type="text/template" id="entry-template">
            <td><%- entry %></td>
            <td><button class="delete">Delete</button></td>
        </script>
    <script src="js/lib/jquery.js"></script>
    <script src="js/lib/underscore.js"></script>
    <script src="js/lib/backbone.js"></script>
    <script src="js/lib/backbone.marionette.js"></script>
    <script src="js/demo.js"></script>
</body>

4

2 に答える 2