我正在使用ember 2.7.0。虽然手动刷新页面ember清除了ember-data以及我们的查询参数,所以我无法在刷新时加载setupController中的页面。是否有任何可能的方法来保留模型和&查询参数,至少保留查询参数可以重新加载我的页面。
route.js
{
"dependencies": {
"Microsoft.AspNet.WebApi.Client": "5.2.3",
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Mvc.WebApiCompatShim": "1.0.0",
"Microsoft.AspNetCore.Razor": "1.0.0",
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview1-final",
"type": "build"
},
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.DependencyInjection": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.Net.Http.Server": "1.0.0-beta6",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
"NLog": "4.3.7",
"NLog.Extensions.Logging": "1.0.0-rtm-alpha4",
"NLog.Interface": "3.2.1",
"PostSharp": "4.3.15"
},
"tools": {
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview1-final",
"imports": "portable-net45+win8+dnxcore50"
},
"Microsoft.AspNetCore.Server.IISIntegration.Tools": {
"version": "1.0.0-preview1-final",
"imports": "portable-net45+win8+dnxcore50"
}
},
"frameworks": {
"net452": {
"dependencies": {
"JECodingTest.Business": {
"target": "project"
}
}
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"publishOptions": {
"include": [
"wwwroot",
"Views",
"appsettings.json",
"web.config"
]
},
"scripts": {
"prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ],
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
任何帮助都应该是值得的。
根据Adam Cooper评论编辑setupController:
model(params) {
return this.store.peekRecord("book",params.book_id);
},
setupController(controller,model,params){
if(!model){
//fetch book record again if the model is null
}
controller.set('isdn',params.queryParams.isdn);
controller.set('book',model);
}
页面在“findRecord”返回promise之前呈现。是否有任何方法可以停止页面呈现,直到找到记录来解析承诺?
答案 0 :(得分:1)
您需要为路线生成实际控制器,然后在控制器中定义queryParams属性。看起来你试图抓住的查询参数是isdn所以你的控制器看起来应该是这样的:
export default Ember.Controller.extend({
queryParams: ['isdn']
});
答案 1 :(得分:1)
您正在设置路线属性而不是控制器..
setupController(controller, model, params){
var isdn = params.queryParams.msisdn;
controller.set('isdn', isdn);
if(!model){
this.store.findRecord('book', isdn).then((customer) => {
controller.set('book', customer);
}, (resp, status) => {
controller.set('errorMessage', `Book with this ${isdn} does not exist.`);
controller.set('book', []);
});
}else{
controller.set('device', model);
}
}
只有控制器属性才能装饰模板。
您甚至可以尝试下面的内容,为什么不给模型挂钩解析的机会,因为这将等待Promises解决。
model(params) {
var result = this.store.peekRecord("book",params.book_id);
if(result !== null){
result= this.store.findRecord('book', params.book_id)
}
return result;
}
setupController(controller,model){
controller.set('book',model);
}