我遇到了EmberJS的问题我无法理解
问题可以在jsfiddle中找到: http://jsfiddle.net/wLKKQ/
JS:
var fileUploader = [] || fileUploader;
fileUploader.app = Em.Application.create();
fileUploader.app.userDetailsView = Em.View.create({
clientIP: null
});
HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<script type="text/x-handlebars">
{{#view fileUploader.app.userDetailsView}}
<h2>Hello Guest, your IP is: {{clientIP}}</h2>
{{/view}}
</script>
<script>
$(function () {
fileUploader.app.userDetailsView.set('clientIP', '::1');
});
</script>
</body>
</html>
我收到以下错误:
未捕获错误:断言失败:无法在路径'fileUploader.app.userDetailsView'找到视图
答案 0 :(得分:2)
您的代码中存在多个问题。
Ember.View.create
替换为Ember.View.extend
。clientIP
的脚本不起作用,因为现在FileUploader.app.userDetailsView
是一个类。您可以使用didInsertElement
Ember.View方法执行相同的操作。view.clientIP
。FileUploader = [] || fileUploader;
FileUploader.app = Em.Application.create();
FileUploader.app.userDetailsView = Em.View.extend({
clientIP: null,
didInsertElement: function() {
this.set("clientIP", "::1");
}
});
HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<script type="text/x-handlebars">
{{#view FileUploader.app.userDetailsView}}
<h2>Hello Guest, your IP is: {{view.clientIP}}</h2>
{{/view}}
</script>
</body>
</html>