gpt4 book ai didi

javascript - 实现 ember js 后网站无法呈现

转载 作者:行者123 更新时间:2023-11-28 17:26:58 25 4
gpt4 key购买 nike

背景

我正在尝试使用 ember.js 及其依赖项构建博客。基本上,我在左侧“导航栏”,内容显示在右侧。像这样的东西:

BLOG LAYOUT

左边不动,右边不动;此外,左侧还有指向各个页面的链接。

问题

我正在使用 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 &mdash; 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>

我的尝试

我尝试制作两个不同的 Handlebars 脚本,一个是对帖子的引用,即

<script type="text/x-handlebars" id="posts">
<section>
<h3> Welcome to my blog </h3>
<p>
{{outlet}}
</p>
</section>
</script>

但这没有用。我还尝试在整个 div 周围制作一个 Handlebars 脚本,但这也没有用。

如果有人能指出问题所在的正确方向:我将永远欠你的债。谢谢! :)

更新我已经更新了 HTML/js 的代码。可以查看here

最佳答案

你错过了一些关于 ember 的想法 -
命名很重要。您有帖子 - 应该在模型中,然后使用夹具适配器来声明它们。您有一个帖子模板,但没有定义或在您的路由器中的帖子路由。

this.resource("posts", {path: "/posts"}, function(){
this.resource("post", {path: "/:post_id"});
});

您的路由器中没有索引路由。

this.resource("index", {path: "/"}, function() {});

从外观上看,您根本没有 Controller 。(尽管现在看起来您不需要它们)

如果您使用的是 ember,我建议您使用 ember-cli。它将帮助您设置应用程序结构并帮助命名约定。 http://www.ember-cli.com/

学习 ember 教程也没有什么坏处——无论是在 ember 站点本身还是在其他站点上的教程。尝试做一个尽可能最新的代码,因为代码移动得如此之快以至于教程很快就会过时。

链接

{{#each post in model}}
<li> {{#link-to "post" post}} {{post.title}} {{/link-to}}</li>
{{/each}}

所以对于链接 - {{#link-to "template"model}} 其中 template 是模板,model 是你通过链接传递的元素。因此,在您的情况下,它是“发布”模板,并且由于您将模型定义为发布在您使用的每个语句中。通过文档 http://emberjs.com/guides/templates/links/#toc_the-code-link-to-code-helper

关于javascript - 实现 ember js 后网站无法呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26996612/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com