将编译的模板与ember.js一起使用时发生模型绑定错误
我正在尝试将ember的模板放在templates文件夹下。相关代码如下:将编译的模板与ember.js一起使用时发生模型绑定错误,ember.js,Ember.js,我正在尝试将ember的模板放在templates文件夹下。相关代码如下: define(["ember","holder","emberData","text!/templates/index.html"],function(Ember,Holder,DS,indexTpl){ window.App = Ember.Application.create(); /*Route definition*/ App.Router.map(function() { // put your rou
define(["ember","holder","emberData","text!/templates/index.html"],function(Ember,Holder,DS,indexTpl){
window.App = Ember.Application.create();
/*Route definition*/
App.Router.map(function() {
// put your routes here
});
App.IndexRoute = Ember.Route.extend({
model: function() {
return this.store.find("listItem");
},
setupController: function(controller, model) {
this._super(controller, model);
Ember.run.next(function (){Holder.run();});
}
});
App.ApplicationView = Ember.View.extend({
defaultTemplate:Ember.Handlebars.compile(indexTpl)
});
App.IndexController = Ember.ArrayController.extend({
});
/*Model definition*/
App.ListItem = DS.Model.extend({
col1 : DS.attr("string"),
col2 : DS.attr("string"),
col3 : DS.attr("string"),
col4 : DS.attr("string")
});
App.ApplicationAdapter = DS.FixtureAdapter.extend();
App.ListItem.reopenClass({
FIXTURES:[...]
});
});
相关模板:
...
{{#each}}
<tr>
<td>{{id}}</td>
<td>{{col1}}</td>
<td>{{col2}}</td>
<td>{{col3}}</td>
<td>{{col4}}</td>
</tr>
{{/each}}
...
你能帮我吗?提前谢谢你的帮助 您正在将索引模板分配给应用程序视图。您的模板现在希望应用程序模型是一个数组,而您还没有定义它。将索引模板指定给索引视图:
App.IndexView = Ember.View.extend({
defulatTemplate: Ember.Handlebars.compile(indexTpl)
});
啊哈,当我看到你的帖子时,我知道我犯了个错误。它起作用了。非常感谢!
App.IndexView = Ember.View.extend({
defulatTemplate: Ember.Handlebars.compile(indexTpl)
});