如何将一个视图移动到另一个视图
how to move one view to another view?
你能告诉我如何从一个页面导航到另一个页面吗?我想展示第二个html按钮点击是如何实现的
我非常喜欢那样。我抵制那样的事件
events: {
'click #click':'moveTonext'
},
moveTonext: function(){
alert('---')
},
我这样做第二页
define([
'jquery',
'underscore',
'backbone',
'text!templates/second.html'
], function ($, _, Backbone, statsTemplate) {
'use strict';
var secondView = Backbone.View.extend({
// Instead of generating a new element, bind to the existing skeleton of
// the App already present in the HTML.
el: '#todoapp',
// Compile our stats template
template: _.template(statsTemplate),
// Delegated events for creating new items, and clearing completed ones.
events: {
},
// At initialization we bind to the relevant events on the `Todos`
// collection, when items are added or changed. Kick things off by
// loading any preexisting todos that might be saved in *localStorage*.
initialize: function () {
this.render();
},
serialize: function () {
return {
message: 'world'
};
},
// Re-rendering the App just means refreshing the statistics -- the rest
// of the app doesn't change.
render: function () {
this.$el.html(this.template());
}
// Add a single todo item to the list by creating a view for it, and
// appending its element to the `<ul>`.
});
return secondView;
})
第二html <h1>second</h1>
这是我的活塞http://plnkr.co/edit/fCXwSrroJP1l6BppjpmD?p=preview
基本上你的按钮应该触发导航,所以click
处理程序应该看起来像这样:
moveToNext: function () {
router.navigate("other/path", { trigger: true });
}
然后,在您的router
代码中,您需要为上述路径添加一个路由处理程序:
routes: {
"other/path": "handleOtherPath"
},
handleOtherPath: function () {
new SecondView();
}
适用于SecondView
代替FirstView
的情况。如果需要附加,可以使用以下机制:
moveToNext: function () {
new SecondView({ el: this.$(secondViewContainerSelector) });
}
这是一个工作的Plunker样本。
相关文章:
- Kendo:我该如何在树视图中创建一个递归的hieiarchy
- 我该如何编写一个CouchDB视图,列出每个存储文档的大小
- 在Angular ui路由器中,如何将事件从一个视图发送到另一个视图
- 当我点击MVC视图中的图像时,如何打开另一个页面
- 需要一个与HTML5<音频>.哪些没有't创建或销毁视图
- 遍历SC.ManyArrray以创建要附加到SproutCore中的另一个视图的自定义视图
- 在Django中,可以在视图中创建一个包含js的变量,然后在循环模板标记中使用它
- ASP.NET angularjs重定向到控制器的另一个视图
- 如何在angularjs中调用局部视图所需的另一个javascript
- d3日历视图:如何将所有内容放在一个svg中,而不是放在几个svg中
- 挖空视图模型函数仅影响最后一个实例
- 在Grails中使用Asset-Pipeline Plugin制作一个视图加载特定的JavaScript
- 通过jquery将网格视图数据发送到另一个页面
- 另一个 UI 视图中的角度 UI 视图
- jquery专注于asp.net mvc部分视图中的一个文本框
- Rails-从一个视图到下一个视图的水平转换
- 从Backbone中的另一个视图调用新视图
- I'当我试图将java脚本加载到web视图中时,我得到了一个空白屏幕
- Ember eror试图注册一个id已在使用的视图
- 用javascript制作一个网格视图图像