余烬渲染子模板

Ember render child template

本文关键字:余烬渲      更新时间:2023-09-26

我试图渲染一个基于什么点击列表视图(父/子视图)的详细信息视图。所以我有嵌套路由如下;

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

我的child/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);
}
});

我的child/details控制器如下

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

我的子模板如下;(我有一个{{outlet}}在我的父/列表模板)

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

虽然我能够对"/myApp/json/" +参数。myCode +"/details"然后得到响应,它不会呈现给子模板

我注意到setupController没有被调用。它必须手动调用还是应该自动调用(请记住,我正在使用嵌套视图)

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

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) {