【发布时间】:2014-11-18 14:24:47
【问题描述】:
背景
我正在尝试使用 ember.js 构建一个博客,它是依赖项。基本上,我的“导航栏”在左侧,内容显示在右侧。类似的东西:
左边不动,右边不动;此外,左侧还有各个页面的链接。
问题
我正在使用ember.js 来实现帖子的链接并将帖子呈现到博客内容端。目前,我的实现没有渲染任何东西。下面是代码:
App = Ember.Application.create({});
var posts = [{
id: '0',
title: 'Title and title',
author: {name: 'Author'},
date: new Date('15-11-2014'),
content: 'Work and work.'
},{
id: '1',
title: "Rails is Omakase",
author: { name: "d2h" },
date: new Date('12-27-2012'),
excerpt: "There are lots of à la carte software environments in this world. Places where in order to eat, you must first carefully look over the menu of options to order exactly what you want.",
body: "I want this for my ORM, I want that for my template language, and let's finish it off with this routing library. Of course, you're going to have to know what you want, and you'll rarely have your horizon expanded if you always order the same thing, but there it is. It's a very popular way of consuming software.\n\nRails is not that. Rails is omakase."
}, {
id: '2',
title: "The Parley Letter",
author: { name: "d2h" },
date: new Date('12-24-2012'),
excerpt: "My [appearance on the Ruby Rogues podcast](http://rubyrogues.com/056-rr-david-heinemeier-hansson/) recently came up for discussion again on the private Parley mailing list.",
body: "A long list of topics were raised and I took a time to ramble at large about all of them at once. Apologies for not taking the time to be more succinct, but at least each topic has a header so you can skip stuff you don't care about.\n\n### Maintainability\n\nIt's simply not true to say that I don't care about maintainability. I still work on the oldest Rails app in the world."
}];
/*
This will load the lists for the template to take
*/
App.ApplicationRoute = Ember.Route.extend({
model: function(){
return posts;
}
});
App.Router.map(function(){
this.resource('post', {path: '/posts/:post_id'});
});
App.PostRoute = Ember.Route.extend({
model: function(params){
return posts[params.post_id];
}
});
/*Some small variables that*/
App.name = "Blog name";
App.tag = "TAG";
App.stub = "Stub";
@import url(https://fonts.googleapis.com/css?family=Lato:300italic,700italic,300,700);
body {
padding:50px;
font:14px/1.5 Lato, "Helvetica Neue", Helvetica, Arial, sans-serif;
color:#777;
font-weight:300;
}
h1, h2, h3, h4, h5, h6 {
color:#222;
margin:0 0 20px;
}
p, ul, ol, table, pre, dl {
margin:0 0 20px;
}
h1, h2, h3 {
line-height:1.1;
}
h1 {
font-size:28px;
}
h2 {
color:#393939;
}
h3, h4, h5, h6 {
color:#494949;
}
a {
color:#39c;
font-weight:400;
text-decoration:none;
}
a small {
font-size:11px;
color:#777;
margin-top:-0.6em;
display:block;
}
.wrapper {
width:860px;
margin:0 auto;
}
blockquote {
border-left:1px solid #e5e5e5;
margin:0;
padding:0 0 0 20px;
font-style:italic;
}
code, pre {
font-family:Monaco, Bitstream Vera Sans Mono, Lucida Console, Terminal;
color:#333;
font-size:12px;
}
pre {
padding:8px 15px;
background: #f8f8f8;
border-radius:5px;
border:1px solid #e5e5e5;
overflow-x: auto;
}
table {
width:100%;
border-collapse:collapse;
}
th, td {
text-align:left;
padding:5px 10px;
border-bottom:1px solid #e5e5e5;
}
dt {
color:#444;
font-weight:700;
}
th {
color:#444;
}
img {
max-width:100%;
}
header {
width:270px;
float:left;
position:fixed;
}
header ul {
list-style:none;
height:40px;
padding:0;
background: #eee;
background: -moz-linear-gradient(top, #f8f8f8 0%, #dddddd 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f8f8f8), color-stop(100%,#dddddd));
background: -webkit-linear-gradient(top, #f8f8f8 0%,#dddddd 100%);
background: -o-linear-gradient(top, #f8f8f8 0%,#dddddd 100%);
background: -ms-linear-gradient(top, #f8f8f8 0%,#dddddd 100%);
background: linear-gradient(top, #f8f8f8 0%,#dddddd 100%);
border-radius:5px;
border:1px solid #d2d2d2;
box-shadow:inset #fff 0 1px 0, inset rgba(0,0,0,0.03) 0 -1px 0;
width:270px;
}
header li {
list-style-type: none;
}
header ul a {
line-height:1;
font-size:11px;
color:#999;
display:block;
text-align:center;
padding-top:6px;
height:40px;
}
strong {
color:#222;
font-weight:700;
}
header ul li + li {
width:88px;
border-left:1px solid #fff;
}
header ul li + li + li {
border-right:none;
width:89px;
}
header ul a strong {
font-size:14px;
display:block;
color:#222;
}
section {
width:500px;
float:right;
padding-bottom:50px;
}
small {
font-size:11px;
}
hr {
border:0;
background:#e5e5e5;
height:1px;
margin:0 0 20px;
}
footer {
width:270px;
float:left;
position:fixed;
bottom:50px;
}
@media print, screen and (max-width: 960px) {
div.wrapper {
width:auto;
margin:0;
}
header, section, footer {
float:none;
position:static;
width:auto;
}
header {
padding-right:320px;
}
section {
border:1px solid #e5e5e5;
border-width:1px 0;
padding:20px 0;
margin:0 0 20px;
}
header a small {
display:inline;
}
header ul {
position:absolute;
right:50px;
top:52px;
}
}
@media print, screen and (max-width: 720px) {
body {
word-wrap:break-word;
}
header {
padding:0;
}
header ul, header p.view {
position:static;
}
pre, code {
word-wrap:normal;
}
}
@media print, screen and (max-width: 480px) {
body {
padding:15px;
}
header ul {
display:none;
}
}
@media print {
body {
padding:0.4in;
font-size:12pt;
color:#444;
}
}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<title>Blog Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<div class="wrapper">
<script type="text/x-handlebars">
<!-- Header which is on the right side. -->
<header>
<h1> {{App.name}} </h1>
<h2>{{App.tag}}</h2>
<p> {{App.stub}}</p>
<!-- Links to the main content -->
<h3> Recent Content </h3>
<!-- Ember code to filter through five most recent posts -->
{{#each post in model}}
<li> {{#linkTo "post" this}} {{post.title}} {{/linkTo}}</li>
{{/each}}
</header>
<!-- Footer -->
<footer>
<p><small>Hosted on GitHub Pages — Theme by <a href="https://github.com/orderedlist">orderedlist</a> with heavy modifications from Jeel Shah</small></p>
</footer>
</script>
<!-- Main content for the day. The rest of the content will be on the left
Ember code will surround this (?)
-->
<script type="text/x-handlebars">
<section>
<h3> Welcome to my blog </h3>
<p>
{{outlet}}
</p>
</section>
</script>
</div>
<!-- javascripts -->
<script src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/2.0.0/handlebars.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/ember.js/1.9.0-beta.1/ember.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
</body>
</html>
我的尝试
我尝试制作两个不同的车把脚本,一个是对帖子的引用,即
<script type="text/x-handlebars" id="posts">
<section>
<h3> Welcome to my blog </h3>
<p>
{{outlet}}
</p>
</section>
</script>
但这没有用。我还尝试围绕整个div 制作一个单独的把手脚本,但这也没有用。
如果有人能指出问题所在的正确方向:我将永远欠你的债。谢谢! :)
更新
我已经更新了HTML/js 的代码。可以查看here
【问题讨论】:
标签: javascript jquery html css ember.js