【发布时间】:2017-03-22 03:15:49
【问题描述】:
我在生产环境中构建 ember 应用时遇到问题,使用 ember serve 所有组件运行良好,但是当我使用 Ubuntu 16.04 将其部署到 Digital Ocean droplet 中时,应用因一个组件而崩溃。
这里有崩溃组件的代码:
import Ember from 'ember';
import pagedArray from 'ember-cli-pagination/computed/paged-array';
export default Ember.Component.extend({
init(){
this._super(...arguments);
this.send('fillQuestions');
},
didDestroyElement(){
this.send('reset');
},
last: false,
toggleModal: false,
aciertos: 0,
errores: 0,
contenido: Ember.computed('questions', function () {
let i = 0,
content = [],
contenido = [];
for (i; i < this.get('questions.length'); i++) {
content.push(this.get('questions.' + i + '.id_question_group.questions'));
}
contenido = [].concat.apply([], content);
return contenido;
}),
count: 0,
page: 1,
perPage: 1,
pagedContent: pagedArray('contenido', {
pageBinding: "page",
perPageBinding: "perPage"
}),
totalPagesBinding: "pagedContent.totalPages",
progressValue: 0,
color: Ember.computed('count', function () {
return new Ember.String.htmlSafe("width: " + this.get('progressValue') + "%;");
}),
actions: {
...(all my actions)
}
});
在我看来,我有这个:
{{#if exam.show_progressbar}}
<div class="progress-bar progress-bar-info" role="progressbar" aria-valuenow={{progressValue}} aria-valuemin="0" aria-valuemax="100" style={{color}}>
<span>{{progressValue}}%</span>
</div>
{{/if}}
{{#if exam.show_time}}
{{countdown-timer autoStart='false' startTime=exam.duration action='saveresponse'}}
{{/if}}
{{#each pagedContent as |result index|}}
<div class="text-center">
<p>{{result.questionID.description}}</p>
<br/><br/>
</div>
<form {{action 'saveresponse' on="submit"}}>
{{radio-group group=result.questionID.temp elements=result.questionID.rows action="updateValues" nombre=result.questionID.description}}
<br/>
<div class="row">
<div class="column text-left">
<button type="button" {{action 'showAlert'}} class="btn btn-primary">
Cancelar
</button>
</div>
</div>
{{#if last}}
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12 text-right">
<div class="column text-right">
<button type="submit" class="btn btn-primary">
Guardar examen
</button>
</div>
</div>
</div>
{{/if}}
</form>
{{/each}}
<div class="pager">
{{page-numbers content=pagedContent currentPage=page action='checkLast'}}
</div>
以下组件中的错误:{{countdown-timer}} 和 {{radio-group}}
倒计时定时器是一个基于ember-cli-timer 的组件,它从设定的时间开始计数到0,而radio-group 组件只有一个radio-button helper。
任何关于为什么在生产中不工作而在本地工作的想法?
2017 年 3 月 23 日更新
使用 chrome 开发者工具我遇到了这个错误,也许这可以解释更多我的问题。
Property set failed: You passed an empty path
2017 年 4 月 24 日更新
我刚刚在组件中发现了确切的错误,这是下一个操作:
actions: {
...
fillQuestions(){
let questions = this.get('contenido'); //Filled with exam questions
for(let i = 0; i < questions.length; i++){
if(questions[i].questionID !== null && questions[i].questionID !== undefined){
console.log(questions[i].questionID.description); //consoles the description of the question
this.set(questions[i].questionID.description, ''); //here it's the problem.
}
}
}
...
}
this.set() 的行是问题所在,因为questions[i].questionID.description 是empty path,有没有办法通过相同的操作在组件中创建新属性?
【问题讨论】:
-
您的exam.duration 是否在传入倒数计时器时设置?您可以添加
{{log exam.duration}}来检查... -
@acorncom 日志显示
{{exam.duration}}不为空,我会尝试查找模板中的所有变量,也许它就是其中之一。 -
你有一个依赖自身的 CP 循环可疑:
contenido: Ember.computed('contenido' -
@locks 我忘了更新,我已经更正了,
Ember.computed它正在寻找“问题”,这是从路由传递的属性。 -
如果您想将描述属性定义为空,那么您可以尝试
this.set(questions[i].questionID.description, ''),而不是this.set(questions[i].questionID.description, '')。在您的情况下,this.set将在组件中创建新属性,这里不需要,因为您没有将其用作属性而不是数组
标签: javascript ember.js digital-ocean