Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用backbone.js将输入值发布到站点的其他区域?_Javascript_Jquery_Html_Backbone.js_Replication - Fatal编程技术网

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

Javascript 如何使用backbone.js将输入值发布到站点的其他区域?,javascript,jquery,html,backbone.js,replication,Javascript,Jquery,Html,Backbone.js,Replication,以下是我试过的一些: $(document).ready(function(){ var checkBoxArray = new Array( "Cleaning&SpecialsInspectionSelect", "PorterServiceSelect", "VacancyInspectionandCleaningSelect", ); }); (i=0;i

以下是我试过的一些:

$(document).ready(function(){
var checkBoxArray = new Array(
              "Cleaning&SpecialsInspectionSelect",
              "PorterServiceSelect",
              "VacancyInspectionandCleaningSelect",
              );
});
(i=0;i{ $(“输入[value=“+checkBoxArray[i]+”]:选中~.“+checkBoxArray[i]).css( “显示”、“继承” ); } 还有一些:

for(i = 0; i < checkBoxArray.length - 1; i++){
    $("input[value=" + checkBoxArray[i] + "]:checked ~ ." + checkBoxArray[i]).css(
    "display", "inherit"
    );
} 
(i=0;i{ var overviewElement=$(“+checkBoxArray[i]).hide(), ifChecked=$(“输入[value=checkBoxArray[i]]”)。单击(函数(){ overviewElement.toggle(ifChecked.is(“:checked”); }); }
谢谢你的帮助

通常的方法是使用全局事件总线。在每个人都能看到的地方复制一份主干网事件:

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"));
    });
}
然后,作为数据源的视图将触发一个事件:

app.event_bus = _({}).extend(Backbone.Events);
另一个视图将监听事件:

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

演示:

数据。我想把文本框中的输入信息输入到网站的另一部分。
app.event_bus.trigger('some_event', data);
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
}