aurelia - Aurelia 模板绑定(bind)错误

标签 aurelia

我想我可能有一个配置问题。循环遍历对象数组时出现错误。这是错误。对象数组正在加载到 View 中,它们看起来是正确的。它只是爆炸的“repeat.for”。

Unhandled promise rejection Error: Incorrect syntax for "for". The form is: "$local of $items" or "[$key, $value] of $items".
at SyntaxInterpreter.for (http://localhost:8080/jspm_packages/github/aurelia/templating-binding@0.13.0/index.js:142:13)
at SyntaxInterpreter.interpret (http://localhost:8080/jspm_packages/github/aurelia/templating-binding@0.13.0/index.js:27:34)
at TemplatingBindingLanguage.createAttributeInstruction (http://localhost:8080/jspm_packages/github/aurelia/templating-binding@0.13.0/index.js:267:46)
at ViewCompiler.compileElement (http://localhost:8080/jspm_packages/github/aurelia/templating@0.13.2/index.js:1442:41)
at ViewCompiler.compileNode (http://localhost:8080/jspm_packages/github/aurelia/templating@0.13.2/index.js:1331:23)
at ViewCompiler.compileElement (http://localhost:8080/jspm_packages/github/aurelia/templating@0.13.2/index.js:1536:31)
at ViewCompiler.compileNode (http://localhost:8080/jspm_packages/github/aurelia/templating@0.13.2/index.js:1331:23)
at ViewCompiler.compileElement (http://localhost:8080/jspm_packages/github/aurelia/templating@0.13.2/index.js:1536:31)
at ViewCompiler.compileNode (http://localhost:8080/jspm_packages/github/aurelia/templating@0.13.2/index.js:1331:23)
at ViewCompiler.compileElement (http://localhost:8080/jspm_packages/github/aurelia/templating@0.13.2/index.js:1536:31)
at ViewCompiler.compileNode (http://localhost:8080/jspm_packages/github/aurelia/templating@0.13.2/index.js:1331:23)
at ViewCompiler.compileNode (http://localhost:8080/jspm_packages/github/aurelia/templating@0.13.2/index.js:1353:33)
at ViewCompiler.compile (http://localhost:8080/jspm_packages/github/aurelia/templating@0.13.2/index.js:1314:12)
at http://localhost:8080/jspm_packages/github/aurelia/templating@0.13.2/index.js:1583:49
at run (http://localhost:8080/jspm_packages/npm/core-js@0.9.18/modules/es6.promise.js:91:43)
at http://localhost:8080/jspm_packages/npm/core-js@0.9.18/modules/es6.promise.js:105:11
at module.exports (http://localhost:8080/jspm_packages/npm/core-js@0.9.18/modules/$.invoke.js:6:25)
at queue.(anonymous function) (http://localhost:8080/jspm_packages/npm/core-js@0.9.18/modules/$.task.js:40:9)
at Number.run (http://localhost:8080/jspm_packages/npm/core-js@0.9.18/modules/$.task.js:27:7)
at listner (http://localhost:8080/jspm_packages/npm/core-js@0.9.18/modules/$.task.js:31:9)

看法

<table class="table">
  <tr>
    <th>Id</th>
    <th>Uploaded Date</th>
    <th>Bathrooms</th>
    <th>Bedrooms</th>
  </tr>
  <tr repeat.for="advert in adverts">
    <td>${advert.Id}</td>
    <td>${advert.DateAdded}</td>
    <td>${advert.Bathrooms}</td>
    <td>${advert.Bedrooms}</td>
  </tr>
</table>


View 模型
import {HttpClient} from 'aurelia-http-client';

export class App {
  constructor() {
  this.http = new HttpClient();
  this.adverts = [];
 }
 activate() {
  return this.http.get('http://localhost/BackEnd/api/adverts')
    .then(response => {
      this.adverts = response.content;
      console.log(this.adverts);
    });
  }
}

最佳答案

repeat.for="advert in adverts"需要repeat.for="advert of adverts"

关于aurelia - Aurelia 模板绑定(bind)错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31302992/

相关文章:

aurelia - 如果 Aurelia 理解 "import",为什么要使用依赖注入(inject)?

javascript - Webpack:无法找到 ID 为 main 的模块 --(Aurelia 应用程序)

javascript - 如何在 Aurelia 应用程序中禁用浏览器同步?

javascript - Aurelia 中 HTML 组件和普通组件的区别?

javascript - 有条件地将 CSS 应用于 Aurelia 中的元素

aurelia - 使用 Aurelia CLI 创建导航骨架项目

typescript - 为什么 Aurelia 会在错误的位置查找文件?

aurelia - @CompatedFrom 抛出 "Cannot set property ' 未定义的依赖项”

aurelia - Symfony 3 形式 + Aurelia

html - 如何刷新 Aurelia 中的子组件以撤消表单?