简体   繁体   English

如何使用骨干.js将输入值发布到站点的其他区域?

[英]How can I use backbone.js to post input values to other areas of a site?

<div class="fmMenu accordion">

    <p class="menuItem">Cleaning &amp Specials Inspection
    <input type="checkbox" name="include" value="Cleaning&SpecialsInspectionSelect" class="headerCheckbox"></p>

    <div><h2>
             Notes<br /><textarea name="Clean&SpecialsInspectionNotes" value="" rows="4" cols"50"></textarea></h2>Start date<input type="text" class="datepicker" />       
    </div>




    <p class="menuItem">Porter Service
    <input type="checkbox" name="include" value="PorterServiceSelect" class="headerCheckbox"></p>
    <div><h2>
             Notes<br /><textarea name="PorterServiceNotes" rows="4" cols"50"></textarea></h2>Start date<input type="text" class="datepicker" />
    </div>



    <p class="menuItem">Vacancy Inspection and Cleaning
    <input type="checkbox" name="include" value="VacancyInspectionandCleaningSelect" class="headerCheckbox" id="joyridestop4"></p>
    <div><h2>
             Notes<br /><textarea name="VacancyInspectionandCleaningNotes" rows="4" cols"50"></textarea></h2>Start date<input type="text" class="datepicker" />
    </div>

</div>

<ol>
                            <li style="display:none" class="Cleaning&SpecialsInspectionSelect">Cleaning &amp Specials Inspection</li>
                            <li style="display:none" class"PorterServiceSelect">Porter Service</li>
                            <li style="display:none" class"VacancyInspectionandCleaningSelect">Vacancy Inspection and Cleaning</li>
</ol>



<div class="showHere"><div>

This is my jQuery accordion. 这是我的jQuery手风琴。 I want to use backbone.js to make it so if you click on the "Cleaning&SpecialsInspectionSelect" checkbox and the "VacancyInspectionandCleaningSelect" checkbox and fill in the other inputs for each one's accordion content, they show up in the "showHere" div. 我想使用bone.js来做到这一点,因此,如果您单击“ Cleaning&SpecialsInspectionSelect”复选框和“ VacancyInspectionandCleaningSelect”复选框,并填写每个人的手风琴内容的其他输入,它们将显示在“ showHere” div中。

Here is some code I've tried. 这是我尝试过的一些代码。 It all uses: 全部使用:

$(document).ready(function(){
var checkBoxArray = new Array(
              "Cleaning&SpecialsInspectionSelect",
              "PorterServiceSelect",
              "VacancyInspectionandCleaningSelect",
              );
});

Here's some I tried: 这是我尝试过的一些方法:

for(i = 0; i < checkBoxArray.length - 1; i++){
    $("input[value=" + checkBoxArray[i] + "]:checked ~ ." + checkBoxArray[i]).css(
    "display", "inherit"
    );
} 

Here's some more: 还有更多:

for(i = 0; i < checkBoxArray.length - 1; i++){
    var overviewElement = $("." + checkBoxArray[i]).hide(),
        ifChecked = $("input[value=checkBoxArray[i]]").click(function(){
            overviewElement.toggle(ifChecked.is(":checked"));
    });
}

Thank you for the help! 感谢您的帮助!

The usual approach is to use a global event bus. 通常的方法是使用全局事件总线。 Make a copy of Backbone.Events somewhere that everyone can see it: 在每个人都能看到的地方复制Backbone.Events

app.event_bus = _({}).extend(Backbone.Events);

Then the view that is the source of the data would trigger an event: 然后,作为数据源的视图将触发一个事件:

app.event_bus.trigger('some_event', data);

and the other view would listen for the event: 另一个视图将监听该事件:

initialize: function() {
    this.listenTo(app.event_bus, 'some_event', this.some_method);
},
some_method: function(payload) {
    // `payload` will be the `data` from the `trigger` call
}

Demo: http://jsfiddle.net/ambiguous/9zD7v/ 演示: http//jsfiddle.net/ambiguous/9zD7v/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM