繁体   English   中英

灰烬渲染子模板

[英]Ember render child template

我试图基于列表视图(父/子视图)上的单击内容渲染详细信息视图。 所以我有如下嵌套的路线;

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}}

虽然我可以对“ / myApp / json /” + params.myCode +“ / details”进行AJAX调用并获得响应,但它不会呈现到子模板中

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM