- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的 route 有一个 setupController
和 model
Hook 。 model.find(param) 保存对 Rails 后端的 ajax 调用。
发生的情况是我的模型钩子(Hook)触发并调用后端。但在后端应答和成功回调实际随模型返回之前,setupController
钩子(Hook)会触发尚未定义的模型。
最终结果是,虽然模型本身通过绑定(bind)系统进行更新,但需要在 setupController 中进行的附加设置不起作用。我感觉我在某种程度上将模型的内容设置错误,但无法弄清楚。
只有当我使用后退和前进按钮进行导航时,才会发生这种情况。如果我通过 #linkTo
进入路线并指定对象,一切都会按预期工作。
我的代码如下,如果有人有一个想法那就太好了。
App.ProjectsEditRoute = Ember.Route.extend({
model: function(params) {
return App.Project.find(params.project_id);
},
setupController: function(controller, model) {
this.controllerFor('activedataset.index').set('content', App.ActiveDataSet.findAll(model.id));
}
});
App.Project = Ember.Object.extend({
id: '',
name: ''
});
App.Project.reopenClass({
findAll: function() {
var result = Ember.ArrayProxy.create({content: []});
var self = this;
$.ajax({
url: '/projects.json',
type: 'GET',
data: {'user_id': App.currentUser.id},
success: function(data, textStatus, xhr) {
result.set('content', data.projects);
},
error: function(xhr, textStatus, errorThrown) {
alert('error');
}
});
return result;
},
find: function(project_id) {
var result = Ember.Object.create({content: null});
var self = this;
$.ajax({
url: '/projects/' + project_id + '.json',
type: 'GET',
success: function(data, textStatus, xhr) {
result.setProperties(data.project);
},
error: function(xhr, textStatus, errorThrown) {
alert('not found');
}
});
return result;
}
});
App.ProjectsEditRoute = Ember.Route.extend({
model: function(params) {
var record = App.Project.find(params.project_id);
var promise = Ember.Deferred.create();
record.addObserver('isLoaded', function() {
promise.resolve(record);
});
return promise;
},
setupController: function(controller, model) {
this.controllerFor('activedataset.index').set('content', App.ActiveDataSet.findAll(model.id));
}
});
App.Project.reopenClass({
find: function(project_id) {
var result = Ember.Object.create({content: null, isLoaded: false});
var self = this;
$.ajax({
url: '/projects/' + project_id + '.json',
type: 'GET',
success: function(data, textStatus, xhr) {
result.setProperties(data.project);
result.set('isLoaded', true);
},
error: function(xhr, textStatus, errorThrown) {
alert('not found');
}
});
return result;
}
});
最佳答案
I have the feeling that I'm somehow setting the content of the model wrong, but can't figure it out.
你的做法本身并没有错。如果您需要 ember 路由器等待模型 ajax 完成,然后再继续 setupController Hook ,您模型的 find() 应该返回一个 promise 。如果路由的模型钩子(Hook)返回一个 promise ,ember 路由器将等待 promise 解决后再继续。
默认情况下,当您调用 find({}) 时,ember-data 的模型对象会返回一个 Promise。对您的模型执行相同操作应该很容易,请参阅此 Ember initializing route model with query获取延迟模式的示例。
This only happens by the way if I use the back and forward button to navigate. If I go in the route through an #linkTo with the object specified everything works as expected.
有道理。当您使用#linkTo 时,数据已加载。
关于routes - model 和 setupController 钩子(Hook)与未定义的模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15508471/
我对 mongoosejs 中模型的使用感到有些困惑。 可以通过这些方式使用 mongoose 创建模型 使用 Mongoose var mongoose = require('mongoose');
我正在看 from django.db import models class Publisher(models.Model): name = models.CharField(max_len
我有自己的 html 帮助器扩展,我用这种方式 model.Reason_ID, Register.PurchaseReason) %> 这样声明的。 public static MvcHtmlS
假设模型原本是存储在CPU上的,然后我想把它移到GPU0上,那么我可以这样做: device = torch.device('cuda:0') model = model.to(device) # o
我过去读过一些关于模型的 MVC 建议,指出不应为域和 View 重用相同的模型对象;但我找不到任何人愿意讨论为什么这很糟糕。 我认为创建两个单独的模型 - 一个用于域,一个用于 View - 然后在
我正在使用pytorch构建一个像VGG16这样的简单模型,并且我已经重载了函数forward在我的模型中。 我发现每个人都倾向于使用 model(input)得到输出而不是 model.forwar
tf.keras API 中的 models 是否多余?对于某些情况,即使不使用 models,代码也能正常运行。 keras.models.sequential 和 keras.sequential
当我尝试使用 docker 镜像运行 docker 容器时遇到问题:tensorflow/serving。 我运行命令: docker run --name=tf_serving -it tensor
我有一个模型,我用管道注册了它: register_step = PythonScriptStep(name = "Register Model",
如果 View 需要访问模型中的数据,您是否认为 Controller 应: a)将模型传递给 View b)将模型的数据传递给 View c)都不;这不应该是 Controller 所关心的。让 V
我正在寻找一个可以在模型中定义的字段,该字段本质上是一个列表,因为它将用于存储多个字符串值。显然CharField不能使用。 最佳答案 您正在描述一种多对一的关系。这应该通过一个额外的 Model 进
我最近了解了 Django 中的模型继承。我使用很棒的包 django-model-utils 取得了巨大的成功。我继承自 TimeStampedModel 和 SoftDeletableModel。
我正在使用基于 resnet50 的双输出模型进行项目。一个输出用于回归任务,第二个输出用于分类任务。 我的主要问题是关于模型评估。在训练期间,我在验证集的两个输出上都取得了不错的结果: - 综合损失
我是keras的新手。现在,我将使用我使用 model.fit_generator 训练的模型来预测测试图像组。我可以使用 model.predict 吗?不确定如何使用model.predict_g
在 MVC 应用程序中,我加入了多个表并将其从 Controller 返回到 View,如下所示: | EmployeeID | ControlID | DoorAddress | DoorID |
我在使用 sails-cassandra 连接系统的 Sails 中有一个 Data 模型。数据。 Data.count({...}).exec() 返回 1,但 Data.find({...}).e
我正在使用 PrimeFaces dataTable 开发一个 jsf 页面来显示用户列表。用户存储在 Model.User 类的对象中。
我正在关注https://www.tensorflow.org/tutorials/keras/basic_classification解决 Kaggle 挑战。 但是,我不明白应该将什么样的数据输入
我是这个领域的新手。那么,你们能帮忙如何为 CNN 创建 .config 文件吗? 传递有关如何执行此操作的文档或教程将对我有很大帮助。谢谢大家。 最佳答案 这个问题对我来说没有多大意义,因为 .co
我是“物理系统建模”主题的新手。我阅读了一些基础文献,并在 Modelica 和 Simulink/Simscape 中做了一些教程。我想问你,如果我对以下内容理解正确: 符号操作是将微分代数方程组(
我是一名优秀的程序员,十分优秀!