1

こんにちは、簡単なことをしようとしています (Marionette + CSS + jquery の初心者であることを考慮してください)。私がやろうとしているのは、ページがロードされたときに特定のクラススタイル(非アクティブスタイルの赤い色)を持つ2つのdivが必要で、ユーザーがそれらの1つをクリックすると、「非アクティブ」クラスを削除し、 「アクティブな」クラス スタイル、緑色を挿入します。私は Marionnette CompositeView を使用して要素をレンダリングしています。問題は、「非アクティブ」クラスが削除されているが、アクティブ クラスが追加されていないことです。問題を次のように単純化します。

<script id="ulTemplate" type="text/template">
    <ul class="ulItem">
    </ul>
</script>
<script id="internal-Item" type="text/template">    
    <div class="<%= className %>"></div>
</script>    
<div class="container">
</div>

私の JS/CSS/コード 親要素に背景を設定している理由 (余分な div CompositeView が追加されています) は、最終結果に私の div に画像が必要だからです。これは非常に単純な例であり、最終的にはより複雑な要素になりますが、今のところ最初のステップ (簡単なステップだと思います) にとどまっています。ここで私を助けてください、私はあなたのコメントに慈悲を持っています。

4

1 に答える 1

0

実際にはコードは機能しており、クラスは変更されていますが、問題は addClasstoParentElement 関数でクラスを「internal-Item-inactive」から「switcher-item-background-active」に変更していることです。そのクラスは、パラメーターとして渡すクラスではなく、css でも定義されていません。

その関数でこの変更を行うと、うまくいきました。

       addClasstoParentElement: function (options) {
           if (!options.element.parent().hasClass(options.className)) {
                options.element.parent().addClass(options.className); // "internal-Item-active"
           }

このリンクを確認してください http://jsfiddle.net/xbBEy/64/

コードと説明を追加しました。

        this.removeClassfromParentElement({element:this.ui.div1, className: "internal-Item-inactive"});
            this.addClasstoParentElement({element: this.ui.div1, className: "internal-Item-active"}); 
            // and here we make the second div Inactive, 
            // this referst to this specific Itemview that indeed contains div1 but does not contains div2 so you cannot use   
           // this.ui.div2 as it will be undefined. thats why is find it using    $('.did2') its  that is traversing the entire dom to find it.
    this.removeClassfromParentElement({element:$('.div2').closest('div'), className: "internal-Item-active"});
            this.addClasstoParentElement({element: $('.div2').closest('div'), className: "internal-Item-inactive"});
于 2013-05-24T15:15:15.907 に答える