灰烬渲染儿童模板

时间:2015-10-16 11:49:39

标签: javascript ember.js ember-data

我正在尝试根据列表视图(父/子视图)上单击的内容呈现详细信息视图。 所以我有如下的嵌套路线;

this.route('my-list', function() {
    this.route('my-details', {
        path: '/details'
    });
});

我的孩子/详情路线如下所示

export default Ember.Route.extend({
model: function(params){
    var detailsUrl = "/myApp/json/" + params.myCode + "/details";
    var detailsRequest = new Ember.RSVP.Promise(function(resolve, reject) {
        Ember.$.ajax({
            url: detailsUrl,
            type: "POST",
            data: JSON.stringify({
                'id': params.Id
            }),
            contentType: 'application/json;charset=utf-8',
            dataType: 'json',
            success: function(response) {
                resolve(response);
            },
            error: function(reason) {
              reject(reason);
            }
        });
    });
    detailsRequest.then(function(response) {
        return response; // I do get the correct response here
    }, function(error) {
    });
},
setupController: function(controller, model) {
    debugger;
    controller.set('model', model);
}
});

我的孩子/细节控制器如下所示

export default Ember.Controller.extend({
    queryParams: ['myCode','Id'],
    productCode: null
});

我的孩子模板如下; (我的父/列表模板中有{{outlet}})

<p>Child details </p>
someId : {{model.someId}}

虽然我能够进行AJAX调用 “/ myApp / json /”+ params.myCode +“/ details” 并获得响应,它没有呈现给子模板

我注意到setupController没有被调用。它是否必须手动调用OR是否自动调用(请记住我使用的是嵌套视图)

1 个答案:

答案 0 :(得分:0)

我看到的第一个错误是你将结果返回到承诺函数而不是模型

export default Ember.Route.extend({

detailsRequest.then(function(response) {
    return response; // I do get the correct response here
}, function(error) {
});

正确的方法应该是

return detailsRequest.then(function(response) {
        return response; // I do get the correct response here
    }, function(error) {
相关问题