简体   繁体   English

灰烬渲染子模板

[英]Ember render child template

I am trying to render a details view based on what gets clicked on the list view (parent/child view). 我试图基于列表视图(父/子视图)上的单击内容渲染详细信息视图。 So I have nested route as below; 所以我有如下嵌套的路线;

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

Also my child/details route looks like below 我的孩子/详细路线也如下

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

And my child/details controller looks like below 我的孩子/细节控制器如下所示

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

And my child template is as below; 我的孩子模板如下: (I have a {{outlet}} in my parent/list template) (我的父母/列表模板中有一个{{outlet}})

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

While I am able to make the AJAX call to "/myApp/json/" + params.myCode + "/details" and get the response, it is not getting rendered to the child template 虽然我可以对“ / myApp / json /” + params.myCode +“ / details”进行AJAX调用并获得响应,但它不会呈现到子模板中

I noticed the setupController not getting called. 我注意到setupController没有被调用。 Does it have to be manually called OR should it get called automatically (Do rememeber I am using a nested view) 是否必须手动调用它,还是应该自动调用它(请记住我正在使用嵌套视图)

First mistake i see is that you're returning the result to the promise function not to the model 我看到的第一个错误是您将结果返回给promise函数而不是模型

export default Ember.Route.extend({

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

Correct way should be 正确的方法应该是

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