在让我的 ember 路由工作时遇到一些麻烦,如果我做得对,我有点困惑。似乎这部分发生了很多变化,这可能有点令人困惑。我希望有人能帮我看看这里出了什么问题。
应用
refset.sparklingideas.co.uk:8000
环境
2013 年 11 月 20 日克隆的 Ember App Kit
Ember : 1.2.0-beta.4
Ember Data : 1.0.0-beta.2
Handlebars : 1.1.2
Query : 1.9.1
Node : v0.10.21
Chrome : 31.0.1650.16 beta
OS X : Maverick
所有源代码都可以在这里找到:
https://github.com/sparkling/snomed-refset
抱歉,还没有成功托管它,但我确实有截图来说明:
http://goo.gl/DGBSvf
问题
我当前的配置有两个问题。
Loading concepts in router ember.js:3227
GETing concepts for: {...} ember.js:3227
Rendering refset.concepts with default view <appkit@view:default::ember404>
Object {fullName: "view:refset.concepts"} ember.js:3227
Transitioned into 'refset.concepts' ember.js:3227
Uncaught TypeError: Cannot read property 'parentNode' of null ember.js:24102
Assertion failed: Emptying a view in the inBuffer state is not allowed and
should not happen under normal circumstances. Most likely there is a bug
in your application. This may be due to excessive property change notifications.
ember.js:3227
Uncaught Error: You cannot modify child views while in the inBuffer state
ember.js:22892
这些有问题的“链接到”语句位于:
'template/refset.hbs' 中的
源可以在上面的链接中找到,也可以在下面复制。
来源
路线
var Router = Ember.Router.extend();
Router.map(function() {
this.resource('refsets', {path:'/'});
this.resource('create', {path:'/create'}, function(){});
this.resource('refset', {path:'/:publicId'}, function(){
this.route('concepts', {path:'/'});
this.route('plan', {path:'plan'});
});
});
Router.reopen({
location: 'history'
});
export default Router;
模板/refset/concepts.hbs
<secion id="concepts">
<h2>Concepts
{{#link-to 'refset.plan' refset}}<button class="toggle btn btn-sm btn-default">Show Rules</button>{{/link-to}}
</h2>
<table id="forums" class="table table-striped">
<thead>
<th>Title</th>
<th>Id</th>
<th>Effective on</th>
<thead>
<tbody>
{{#each concept in controller}}
<tr>
<td><a {{bind-attr href=concept.href}} target="_blank">{{concept.title}}</a></td>
<td>{{concept.id}}</td>
<td>{{date-format concept.effectiveTime}}</td>
</tr>
{{/each}}
</tbody>
</table>
</section>^0k334q5PK3Wcn#p^4CS#
模板/refset/plan.hbs
<secion id="plan">
<h2>Plan
{{#link-to 'refset.concepts' refset}}<button class="toggle btn btn-sm btn-default">Show Concepts</button>{{/link-to}}
</h2>
<ul class="list-group">
{{#each rule in rules}}
<li class="list-group-item">
{{show-rule rule}}
</li>
{{/each}}
</ul>
<div class="terminal">Terminal: {{terminal}}</div>
</section>
模板/refset.hbs
<ol class="breadcrumb">
<li>{{#link-to 'refsets'}}Refsets{{/link-to}}</li>
<li class="active">{{title}}</li>
</ol>
<h1>{{title}}</h1>
<section id="details">
{{outlet details}}
<section id="details">
Controller /refset/concepts.js
export default Ember.ArrayController.extend({
conceptsResponse: 'concepts-response-not-set',
needs: "refset",
refset: Ember.computed.alias("controllers.refset.model")
});
Controller /refset/plan.js
export default Ember.ObjectController.extend({
planResponse: 'plan-response-not-set',
needs: "refset",
refset: Ember.computed.alias("controllers.refset")
});
Controller /refset.js
export default Ember.ObjectController.extend({});
路线/refset/concepts.js
import Refset from 'appkit/models/refset';
export default Ember.Route.extend({
model: function() {
Ember.Logger.log('Loading concepts in router');
return Refset.getConcepts(this.modelFor('refset'), this);
},
renderTemplate: function(){
this.render({outlet:'details'});
}
});
路线/引用/plan.js
import Refset from 'appkit/models/refset';
export default Ember.Route.extend({
model: function() {
Ember.Logger.log('Loading plan in router');
return Refset.getPlan(this.modelFor('refset'), this);
},
renderTemplate: function(){
this.render({outlet:'details'});
}
});
路线/refset.js
import Refset from 'appkit/models/refset';
export default Ember.Route.extend({
model: function(args) {
return Refset.loadRefset(args.publicId, this);
}
});
JSON AJAX 响应
计划/规则
{
"id":25,
"terminal":67,
"rules":[
{
"id":65,
"type":"LIST",
"left":null,
"right":null,
"concepts":[
{
"id":321987003,
"title":"Citalopram 20mg tablet (product)",
"active":false,
"effectiveTime":0
},
{
"id":441519008,
"title":"Contusion of infraorbital nerve (disorder)",
"active":false,
"effectiveTime":0
},
{
"id":17783003,
"title":"Car sickness (finding)",
"active":false,
"effectiveTime":0
},
{
"id":128665000,
"title":"Pituitary carcinoma (morphologic abnormality)",
"active":false,
"effectiveTime":0
}
]
},
{
"id":66,
"type":"LIST",
"left":null,
"right":null,
"concepts":[
{
"id":254597002,
"title":"Oleogranuloma of intestine (disorder)",
"active":false,
"effectiveTime":0
},
{
"id":412398008,
"title":"Griseofulvin microsize (product)",
"active":false,
"effectiveTime":0
},
{
"id":118831003,
"title":"Procedure on intestine (procedure)",
"active":false,
"effectiveTime":0
}
]
},
{
"id":67,
"type":"UNION",
"left":65,
"right":66,
"concepts":[
]
}
]
}
概念
{
"concepts":[
{
"id":321987003,
"href":"http://browser.snomedtools.com/version/1/concept/xml/321987003",
"serialisedId":0,
"title":"Citalopram 20mg tablet (product)",
"effectiveTime":20020131,
"active":true
},
{
"id":441519008,
"href":"http://browser.snomedtools.com/version/1/concept/xml/441519008",
"serialisedId":0,
"title":"Contusion of infraorbital nerve (disorder)",
"effectiveTime":20090731,
"active":true
},
{
"id":17783003,
"href":"http://browser.snomedtools.com/version/1/concept/xml/17783003",
"serialisedId":0,
"title":"Car sickness (finding)",
"effectiveTime":20020131,
"active":true
},
{
"id":128665000,
"href":"http://browser.snomedtools.com/version/1/concept/xml/128665000",
"serialisedId":0,
"title":"Pituitary carcinoma (morphologic abnormality)",
"effectiveTime":20020131,
"active":true
},
{
"id":254597002,
"href":"http://browser.snomedtools.com/version/1/concept/xml/254597002",
"serialisedId":0,
"title":"Oleogranuloma of intestine (disorder)",
"effectiveTime":20020131,
"active":true
},
{
"id":412398008,
"href":"http://browser.snomedtools.com/version/1/concept/xml/412398008",
"serialisedId":0,
"title":"Griseofulvin microsize (product)",
"effectiveTime":20040731,
"active":true
},
{
"id":118831003,
"href":"http://browser.snomedtools.com/version/1/concept/xml/118831003",
"serialisedId":0,
"title":"Procedure on intestine (procedure)",
"effectiveTime":20020131,
"active":true
}
]
}
引用
[
{
"id":41,
"concept":{
"id":2189000,
"href":"http://browser.snomedtools.com/version/1/concept/xml/2189000",
"serialisedId":0,
"title":"Hemoglobin F-Dammam (substance)",
"effectiveTime":20020131,
"active":true
},
"publicId":"ffff",
"title":"fffff",
"description":"ffffff",
"created":"2013-11-24",
"lastModified":"2013-11-24"
},
{
"id":44,
"concept":{
"id":27089009,
"href":"http://browser.snomedtools.com/version/1/concept/xml/27089009",
"serialisedId":0,
"title":"Blood group antibody Ce (substance)",
"effectiveTime":20020131,
"active":true
},
"publicId":"qqqqqqqqqqq",
"title":"qqqqqqq",
"description":"qqqqqqq",
"created":"2013-11-25",
"lastModified":"2013-11-25"
},
{
"id":23,
"concept":{
"id":21304000,
"href":"http://browser.snomedtools.com/version/1/concept/xml/21304000",
"serialisedId":0,
"title":"Hemoglobin A,c (substance)",
"effectiveTime":20020131,
"active":false
},
"publicId":"sdsdawaesf",
"title":"sdsdsdsd",
"description":"sdsdsdsd",
"created":"2013-10-10",
"lastModified":"2013-10-10"
},
{
"id":21,
"concept":{
"id":2156000,
"href":"http://browser.snomedtools.com/version/1/concept/xml/2156000",
"serialisedId":0,
"title":"Glial cell (cell)",
"effectiveTime":20020131,
"active":true
},
"publicId":"heyho",
"title":"This is a sample refset",
"description":"and I am a sample description",
"created":"2013-10-09",
"lastModified":"2013-10-09"
}
]
helper
显示规则
export default Ember.Handlebars.makeBoundHelper(function(rule) {
if (rule.get('type') === 'LIST'){
return new window.Handlebars.SafeString("<span style=\"color: lightgrey\">" + rule.get('id') + "</span> <strong>List</strong> <span style=\"padding-left: 0.5em;color:grey\">[" + rule.get('concepts').length + "]</span>");
}
else if (rule.get('type') === 'UNION'){
return new window.Handlebars.SafeString("<span style=\"color: lightgrey\">" + rule.get('id') + "</span> <strong></strong>Rule " + rule.get('left') + " <strong>Union</strong> Rule " + rule.get('right'));
}
else if (rule.get('type') === 'DIFFERENCE'){
return new window.Handlebars.SafeString("<span style=\"color: lightgrey\">" + rule.get('id') + "</span> <strong></strong>Rule " + rule.get('left') + " <strong>Difference</strong> Rule " + rule.get('right'));
}
else if (rule.get('type') === 'SYMMETRIC'){
return new window.Handlebars.SafeString("<span style=\"color: lightgrey\">" + rule.get('id') + "</span> <strong></strong>Rule " + rule.get('left') + " <strong>Symmetric Difference</strong> Rule " + rule.get('right'));
}
else if (rule.get('type') === 'INTERSECTION'){
return new window.Handlebars.SafeString("<span style=\"color: lightgrey\">" + rule.get('id') + "</span> <strong></strong>Rule " + rule.get('left') + " <strong>Intersection</strong> Rule " + rule.get('right'));
}
});
最佳答案
大多数时候我看到这与无效的 HTML、不匹配的 div/部分等有关。
<section id="details">
{{outlet details}}
<section id="details">
应该
<section id="details">
{{outlet details}}
</section>
在 plan.hbs 中
section
被拼错为 secion
。另外使用/作为概念路径似乎令人困惑 ember,它认为末尾带有/的 url 仍然只是 refset (不是概念)
Router.map(function() {
this.resource('refsets', {path:'/'});
this.resource('create', {path:'/create'}, function(){});
this.resource('refset', {path:'/:publicId'}, function(){
this.route('concepts', {path:'concepts'});
this.route('plan', {path:'plan'});
});
});
关于ember.js - Ember 链接抛出错误/未按预期清除屏幕,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20204909/