- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我尝试使用Compound.js 创建一个博客。我有两个表,“类别”和“帖子”,每个表都有日期属性,但是当我生成表时,我得到了一个表单,其中每个"new" View 中都有日期属性的输入...
我想在创建它时自动更新 Controller 中的日期属性。
我该如何制作?
我的舍玛:
var Category = describe('Category', function () {
property('name', String);
property('date', Date);
set('restPath', pathTo.categories);
});
var Post = describe('Post', function () {
property('title', String);
property('content', String);
property('published', Boolean);
property('date', Date);
set('restPath', pathTo.posts);
});
Category.hasMany(Post, {as: 'posts', foreignKey: 'categoryId'});
我的模型:
module.exports = function (compound, Category) {
// define Category here
};
我的 Controller :
action('new', function () {
this.title = 'New category';
this.category = new Category;
render();
});
action(function create() {
Category.create(req.body.Category, function (err, category) {
respondTo(function (format) {
format.json(function () {
if (err) {
send({code: 500, error: category && category.errors || err});
} else {
send({code: 200, data: category.toObject()});
}
});
format.html(function () {
if (err) {
flash('error', 'Category can not be created');
render('new', {
category: category,
title: 'New category'
});
} else {
flash('info', 'Category created');
redirect(path_to.categories);
}
});
});
});
});
最佳答案
如果您希望默认设置日期,您可以在架构中这样做:
var Category = describe('Category', function () {
property('name', String);
property('date', Date, {default: new Date});
set('restPath', pathTo.categories);
});
如果您不希望用户看到日期字段,您可以将其从 View 标记中删除,因为数据对象已预先填充。
关于node.js - 使用Compound.js 更新 Controller 中的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15578362/
假设有一条SQL语句: select * from A order by cola 在sqlalchemy中,我们可以使用以下代码: session.query(A).order_by(asc(col
在语句中调用函数sum(int [], arr_size) total = sum((int []){1,2,3,4,5}, 5); 复合文字 (int []){1,2,3,4,5} 作为参数传递。很
有一个MySQL的查询。这种查询在前端很容易解决,但需要MySQL中的一种机制。你如何计算 1 列中的 2 个不同项目?例如:我有这张 table : NAME FRUIT A APPLE
我有一个功能齐全的复合 PostgreSQL 查询... SELECT * FROM (SELECT date_trunc('day', date) date, (array_agg(open ORD
我有一个 LINQ 实体,我需要为其创建一个特殊的字符串值。它是由“-”分隔的 7 个不同的值。使用的一些字段在该表中,而其中一些在不同的表中。我想以某种方式将这个字段添加到实体中,这样我就不必在每次
我正在实现我自己的内容提供程序,因为我要将我的数据库与服务器同步。我的数据存储在 SQLiteDatabase 中,我的一些表有一个复合主键(2 列,每列都是另一个表的外键)。 我刚开始使用 Cont
我想用复合位图创建一个 TextView,我知道 android 支持用复合可绘制对象创建 TextView,但我想在在线下载图片时复合位图 注意:我不想让 LinearLayout 包含 image
我正在尝试读取 .pdb 文件,因此我的代码中有很多变量。为了减少它们(并避免段错误),我想知道是否可以使用外部参数在我的代码中分配数组名称。 我的代码 foo.cpp 的起始位看起来像这样- /*A
我想弄清楚如何更改按钮左侧可绘制图标的颜色。 下面是我使用的 XML 代码: 我试过 android:tint 但图标的颜色没有改变。我被困在这里。 最佳答案 您可以像下面这样以编程方式设置色调
我试图将 jade 设置为复合 js 中的默认模板引擎。当我浏览我发现的文档时 Templating engines By default railway use ejs templating eng
我对复合触发器有疑问。 :new.value 在每一行之前部分是空白/空的,当一个之后部分被指定。 创建表格部分: DROP TABLE test_tab; CREATE TABLE test
正如标题所说,我如何加入/约束 2 个 pymunk 体/形状,使它们不作为一个单独的对象? 例如,在这种情况下,我有一个板 Racket ,由 2 个独立的主体和多边形组成。 我想将 bat 的“
Tridion 模板生成器错误 从模板生成器打开复合模板时,我们收到错误消息 “无法加载文件或 Assembly Tridion.ContentManager.TemplateTypes Ver 5.
我正在编写一个金融市场数据分发应用程序作为我的 M.S 项目的一部分。该应用程序即将完成,但该应用程序的扩展性不佳。 这就是它的工作原理,我订阅了一个“假”交易所来获取市场数据。 订阅后,我得到一个初
是否可以定义一个 CSS 样式,使其默认包含另一个样式? 例如,参加以下类(class): .rounded{ -webkit-border-radius:5px; -moz-border-r
我有一个 Activity 表,其中显示哪些用户关注谁。 (fromUser 和 toUser)我正在构建一个排行榜,以查看关注者中谁的评分最高。 所以我创建了这个查询: ParseQuery que
我正在尝试使用 获取以下每个元素 element = driver.findElement(By.className("code-list-item code-list-item-public "))
我有 2 个表,结构如下: CREATE TABLE `exp_ws_gk_text` ( `WGT_RID` INT(9) NOT NULL AUTO_INCREMENT, `WGT
我有一个包含指向回调函数的指针的结构,如下所示: typedef void (*LOAD_CB)(resource* r); typedef void (*UNLOAD_CB)(resou
我正在使用 C++ amp 编写模拟代码。我有以下问题,但找不到明确的答案。希望有人能帮忙。实际上,它们是相互关联的。 我写了一些像这样的行并且它有效,我已经测试了结果但我需要有人指出它为什么是对或错
我是一名优秀的程序员,十分优秀!