我在学习ember.js和ember-cli时遇到了很多困难,主要是试图将ember.js的帮助文档翻译成ember-cli环境。我一直在试图弄清楚如何使用除'id'之外的字段的动态段。Ember和Ember-cli动态路由问题
在Emberjs.com它给出了一个使用jQuery.getJSON和序列化功能的例子,但我不知道
1)如何从灰烬-CLI参考的jQuery(如果我甚至需要做到这一点的上面的链接说来),并
2)好像不管我怎么努力,我得到的错误
我目前使用transitionToRoute
“不能打电话的‘未定义’GET方法”在我的序列化功能因为我试图从一个按钮而不是link-to
帮手转换(更好的建议非常好来)。
这里的行动我的按钮使用(这是在控制器):
actions: {
viewDetails: function() {
this.transitionToRoute('project-details', this.get('projectName'));
}
}
如果我的路线是:
this.resource('project-details', {path: '/project/:project_projectName'});
然后灰烬文档建议,这是在我的项目细节路线中需要什么,但是我没有得到序列化程序的任何组合,所以我确信我做错了什么,但我不知道是什么。
model: function(params) {
//I've tried all kinds of things in here, not sure if I need getJSON
// since right now I'm just using fixture data
//If I do need jQuery, not sure how to use it in ember-cli (i.e. the import statement to use)
return jQuery.getJSON('/project/' + params.project_projectName);
},
serialize: function(model) {
return { project_projectName: model.get('projectName') };
}
编辑:添加模型
var Project = DS.Model.extend({
creationDate: attr('date'),
lastModifiedDate: attr('date'),
lastModifiedResourceId: attr('string'),
ppmcNumber: attr('number'),
ppmcUrl: attr('string'),
phase: attr('string'),
staffingProfile: attr('string'),
projectType: attr('string'),
projectDesc: attr('string'),
product: attr('string'),
clientId: attr('string'),
clientName: attr('string'),
overallStatus: attr('string'),
liveDate: attr('date'),
rygStatus: function(){
return 'status-' + this.get('overallStatus').toLowerCase();
}.property('overallStatus')
});
定义了“projectName”的位置?我假设这个错误是因为“get”没有找到它的值。 – Grapho 2014-08-27 13:13:48
@Grapho:项目名称在项目模型上定义。该错误是说它不能访问“未定义”的“get”方法,我认为它不知道模型是什么,所以它不能执行get方法。 – redOctober13 2014-08-27 13:57:42
我有点困惑,你的模型是烬数据,但你使用$ .getJSON。你什么时候创建/使用该烬数据模型? – Kingpin2k 2014-08-27 23:30:14