Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.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
Backbone.js 如何修改主干视图';钥匙在飞吗?_Backbone.js - Fatal编程技术网

Backbone.js 如何修改主干视图';钥匙在飞吗?

Backbone.js 如何修改主干视图';钥匙在飞吗?,backbone.js,Backbone.js,我已经创建了主干视图a和B: var App = { run: function () { this.aview = new aView(); this.bview = new bView(); } }; // First View var aView = Backbone.View.extend({ el: '#a', render: function () { this.$el.html('foobar A')

我已经创建了主干视图
a
B

var App = {
    run: function () {
        this.aview = new aView();
        this.bview = new bView();
    }
};

// First View
var aView = Backbone.View.extend({
    el: '#a', 
    render: function () {
       this.$el.html('foobar A');
    }        
});

// Second View
var bView = Backbone.View.extend({
    el: '#b', 
    render: function () {
       this.$el.html('foobar B');

       // want to put `foobar A` content into #c which is inside #b 
       // but aView's el lets it be into #a.
       // One Possible solution would be to create a new instance of aView 
       // and change its `el` 
       var tempaView = new aView({ el: '#c' });
       tempaView.render();  // Now it puts `foobar A` into #c 
       // Or another solution would be to pass a new element as a param to 
       // App.aview.render('#c'); and check whether param is undefined, otherwise
       // the content will be added into #param (in this case #c). 
    }
});


App.aview.render(); // Puts `foobar A` into <body>        
App.bview.render(); // Puts `foobar B` into #b and `foobar A` into #c
var-App={
运行:函数(){
this.aview=新的aview();
this.bview=新bview();
}
};
//第一视图
var aView=Backbone.View.extend({
el:“#a”,
渲染:函数(){
这个.$el.html('foobar A');
}        
});
//第二视图
var bView=Backbone.View.extend({
el:“#b”,
渲染:函数(){
这个.$el.html('foobar B');
//要将'foobar A'内容放入#b内的#c中吗
//但阿维的el让它进入了a。
//一个可能的解决方案是创建一个新的aView实例
//并改变它的“el”
var tempaView=新的aView({el:'#c'});
tempaView.render();//现在它将'foobar A'放入#c
//或者另一种解决方案是将新元素作为参数传递给
//App.aview.render(“#c”);并检查参数是否未定义,否则
//内容将添加到#param中(在本例中为#c)。
}
});
App.aview.render();//将'foobar A'放入
App.bview.render();//将'foobar B'放在#B中,将'foobar A'放在#c中
那么,我的问题是,哪种方法是正确的?
除了这个,还有谁有更好的解决方案吗?

太棒了。我应该有RTFM;-)