Ember route model()错误和model()数据不会显示在相关的hbs模板中

时间:2017-05-09 22:35:28

标签: ember.js ember-cli

代码: https://gist.github.com/dmitry-saritasa/85d2b73b7f28903486e61cfa719ccdd1

你可以在这里玩 https://ember-twiddle.com/85d2b73b7f28903486e61cfa719ccdd1?openFiles=routes.my-route.js%2C&route=%2Fmy-route

export default Ember.Route.extend({
  model: function() {
    var companies = [{
      "name" : "Google",
      "headquarters": "Mountain View, California, United States of America",
      "revenue":"59825000000"
    },{
      "name" : "Facebook",
      "headquarters":"Menlo Park, California, United States of America",
      "revenue":"7870000000"
    },{
      "name" : "twitter",
      "revenue": "664000000",
      "headquarters":"San Francisco, California, United States of America"
    }];
    return companies;
  };
});

收到以下错误

ember-twiddle-f01fea9….js:2 SyntaxError: routes/my-route.js: unknown: Unexpected token (17:3)
    }];
    return companies;
  };
});
    at t.default.raise (vendor-9da9463….js:75)
    at t.s.unexpected (vendor-9da9463….js:76)
    at t.s.expect (vendor-9da9463….js:76)
    at t.s.parseObj (vendor-9da9463….js:75)
    at t.s.parseExprAtom (vendor-9da9463….js:75)
    at t.parseExprAtom (vendor-9da9463….js:77)
    at t.s.parseExprSubscripts (vendor-9da9463….js:75)
    at t.s.parseMaybeUnary (vendor-9da9463….js:75)
    at t.s.parseExprOps (vendor-9da9463….js:75)
    at t.s.parseMaybeConditional (vendor-9da9463….js:75)
在关联的hbs模板中,

来自route.model()的数据不会显示 enter image description here

我做错了什么?

2 个答案:

答案 0 :(得分:1)

该错误表示第17行有语法错误,您需要};来解决此错误需要删除;
- each阻止语法已更改{{#each model as |item|}}
- 删除了已被弃用的bind-attr。您可以像使用其他属性绑定class={{className}}

一样使用它

Twiddle link

答案 1 :(得分:1)

试一试:

MY-route.hbs

my-route
<hr size=1 />
{{input type="text" value=firstName disabled=nameDisabled size="40"}}

<table id="t01">
 <tr>
   <th>Company Name</th>
   <th>Headquarters</th>
   <th>revenue</th>
 </tr>
 {{#each model as |item|}}
 <tr>
  <td >{{item.name}}</td>
  <td class={{className}}>{{item.headquarters}}</td>
  <td>{{item.revenue}}</td>
 </tr>
 {{/each}}
</table>
<button {{action "toggleColor"}}> Change color </button>

我相信一些旧的句柄表达式已被弃用,例如bind-attr