我在windows上运行的ember上有这个奇怪的错误。我正在复制此代码以进行选择
inputs.hbs:
<h1>All inputs</h1>
<input id="register-input-1" type="text" placeholder="username">
<form action="">
{{input type="radio" name="type" value="foo" }}Foo<br>
{{input type="radio" name="type" value="bar"}}Bar
{{input type="text" name="type" placeholder="type in here"}}
{{view "select" content=names}}
</form>
控制器:
export default Ember.Controller.extend({
selectedName: 'Tom',
names: ["Yehuda", "Tom"]
});
但是我收到了这个错误:
Uncaught Error: Assertion Failed:
The value that #each loops over must be an Array. You passed [Yehuda,Tom]
从这里复制: http://emberjs.com/api/classes/Ember.Select.html
这是我的依赖:
bower:
{
"dependencies": {
"jquery": "^1.11.1",
"ember": "1.11.0",
"ember-data": "1.0.0-beta.16.1",
"ember-resolver": "~0.1.15",
"loader.js": "ember-cli/loader.js#3.2.0",
"ember-cli-shims": "ember-cli/ember-cli-shims#0.0.3",
"ember-cli-test-loader": "ember-cli-test-loader#0.1.3",
"ember-load-initializers": "ember-cli/ember-load-initializers#0.0.2",
"ember-qunit": "0.3.0",
"ember-qunit-notifications": "0.0.7",
"qunit": "~1.17.1"
}
}
包:
{
"scripts": {
"start": "ember server",
"build": "ember build",
"test": "ember test"
},
"engines": {
"node": ">= 0.10.0"
},
"author": "",
"license": "MIT",
"devDependencies": {
"broccoli-asset-rev": "^2.0.2",
"ember-cli": "0.2.2",
"ember-cli-app-version": "0.3.3",
"ember-cli-content-security-policy": "0.4.0",
"ember-cli-dependency-checker": "0.0.8",
"ember-cli-htmlbars": "0.7.4",
"ember-cli-ic-ajax": "0.1.1",
"ember-cli-inject-live-reload": "^1.3.0",
"ember-cli-qunit": "0.3.9",
"ember-cli-uglify": "1.0.1",
"ember-data": "1.0.0-beta.16.1",
"ember-export-application-global": "^1.0.2",
"ember-disable-prototype-extensions": "^1.0.0"
},
"keywords": [
"ember-addon"
],
"dependencies": {
"ember-cli-babel": "^4.0.0"
},
"ember-addon": {
"configPath": "tests/dummy/config"
}
}
答案 0 :(得分:1)
根据我们的评论,您好像有prototype extensions disabled。简而言之,Ember.js使用其他方法扩展了许多内置的全局对象,例如Array。它这样做是为了符合它的对象模型和观察者系统所需的API。但是,Ember团队意识到并不是每个人都可以修改内置对象,所以它的目标是禁用这些扩展。这样做的缺点是Ember仍然需要程序中的所有对象符合它所需的API。
这就是Ember.A()
的来源。Ember.A()
采用一个普通的旧Javascript数组(没有启用扩展)并用EmberNativeArray
包装它。这可以确保数组符合所需的API,但不必修改内置的Array原型来执行此操作。
简而言之,如果您禁用了原型扩展,则必须在上调用{em>每个阵列上的Ember.A()
.Ember将在某个时刻使用它。无论是数组文字(如代码中)还是从第三方库返回的数组,必须调用Ember.A(array)
才能将其提交给Ember。