mirror of
https://github.com/zhigang1992/m.combee.co.git
synced 2026-04-29 03:25:05 +08:00
Add postview, now able to receive post from server
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
define(['backbone', 'moment'], function(Backbone, moment) {
|
||||
var Recipt = Backbone.Model.extend({
|
||||
urlRoot: '/api/v1/receipts',
|
||||
title: function() {
|
||||
return this.get('post').title;
|
||||
},
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
define(['backbone', 'views/login', 'views/index'], function (Backbone, LoginView, IndexView){
|
||||
define([
|
||||
'backbone',
|
||||
'views/login',
|
||||
'views/index',
|
||||
'views/posts'
|
||||
], function (Backbone, LoginView, IndexView, PostsView){
|
||||
var AppRouter = Backbone.Router.extend({
|
||||
routes: {
|
||||
'': 'index',
|
||||
@@ -22,8 +27,11 @@ define(['backbone', 'views/login', 'views/index'], function (Backbone, LoginView
|
||||
appRouter.on("route:showLogin", function (){
|
||||
loginView.render();
|
||||
});
|
||||
var postView = new PostsView({
|
||||
el: $("#content")
|
||||
});
|
||||
appRouter.on("route:showPost", function(id){
|
||||
console.log(id);
|
||||
postView.render({id: id});
|
||||
});
|
||||
appRouter.on("route:defaultAction", function (){
|
||||
appRouter.navigate("/login");
|
||||
|
||||
1
app/scripts/templates/post.html
Normal file
1
app/scripts/templates/post.html
Normal file
@@ -0,0 +1 @@
|
||||
<%= receipt.get('post').title %>
|
||||
@@ -12,7 +12,7 @@
|
||||
<span class="title"> <%= receipt.title() %> </span>
|
||||
</div>
|
||||
<div class="receipt-body">
|
||||
<a href="#posts/<%= receipt.get('post').id %>">
|
||||
<a href="#posts/<%= receipt.id %>">
|
||||
<%= receipt.get('post').body %>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,16 @@
|
||||
define(['backbone'], function(Backbone) {
|
||||
define(['backbone', 'models/receipt', 'text!templates/post.html'], function(Backbone, Receipt, Template) {
|
||||
var PostView = Backbone.View.extend({
|
||||
|
||||
render: function(options) {
|
||||
var view = this;
|
||||
var receipt = new Receipt({
|
||||
id: options.id
|
||||
});
|
||||
receipt.fetch({
|
||||
success: function(receipt) {
|
||||
view.$el.html(_.template(Template, {receipt: receipt}));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
return PostView;
|
||||
});
|
||||
Reference in New Issue
Block a user