我试图将所有项目水平放置在每一行中 RecyclerView
我尝试了很多东西:RelativeLayout作为父亲,然后使用layout_centerInParent,使用基本的android:layout_gravity ="center",尝试添加一些空间元素,使用权重和....
item_row.xml
但我没有成功:(
是)我有的

我想要的是

在活动中
recyclerView.setLayoutManager(new GridLayoutManager(this, 3));
Run Code Online (Sandbox Code Playgroud)
item_row.xml
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/cardView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
card_view:cardCornerRadius="2dp"
card_view:cardElevation="4dp"
card_view:cardUseCompatPadding="true">
<!-- Recycler View Item Row -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/imgThumbnail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:background="@android:color/black" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="item name"
android:id="@+id/txtName"
android:layout_margin="5dp"
android:singleLine="false"
android:lines="2"
android:gravity="center" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="@+id/txtCategory"
android:textStyle="italic"
android:textColor="#496fa9"
android:text="subtitle"
android:layout_weight="1"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:layout_gravity="center" />
<ImageButton
android:id="@+id/imageButton"
android:layout_width="48dp"
android:layout_height="wrap_content"
android:background="@android:color/black"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:padding="8dp"/> …Run Code Online (Sandbox Code Playgroud) android android-layout gridlayoutmanager android-recyclerview
我是 NEST JS 的新手,现在我尝试在 DTO 中包含一些验证器,如下所示:
// /blog-backend/src/blog/dto/create-post.dto.ts
import { IsEmail, IsNotEmpty, IsDefined } from 'class-validator';
export class CreatePostDTO {
@IsDefined()
@IsNotEmpty()
title: string;
@IsDefined()
@IsNotEmpty()
description: string;
@IsDefined()
@IsNotEmpty()
body: string;
@IsEmail()
@IsNotEmpty()
author: string;
@IsDefined()
@IsNotEmpty()
datePosted: string;
}
Run Code Online (Sandbox Code Playgroud)
但是当我执行邮政服务时,例如:
{
"title":"juanita"
}
Run Code Online (Sandbox Code Playgroud)
其回报良好!但是验证器应该显示错误吗?
我的后置控制器
@Post('/post')
async addPost(@Res() res, @Body() createPostDTO: CreatePostDTO) {
console.log(createPostDTO)
const newPost = await this.blogService.addPost(createPostDTO);
return res.status(HttpStatus.OK).json({
message: 'Post has been submitted successfully!',
post: newPost,
});
}
Run Code Online (Sandbox Code Playgroud)
我的 main.ts
import { NestFactory } from …Run Code Online (Sandbox Code Playgroud) 我希望模型绑定id在检索给定模型时不使用表列,并且我getKeyName在Model类中进行覆盖(Service在这种情况下),但是它不起作用!
class Service extends Model{
//override
public function getRouteKey() {
return 'key';
}
}
Run Code Online (Sandbox Code Playgroud)
服务表:
id | key(string,unique) | name(string)
Run Code Online (Sandbox Code Playgroud)
我的路线文件:
Route::resource('services', 'ServiceController');
Run Code Online (Sandbox Code Playgroud)
并在ServiceController:
public function show(Service $service) {
return $service;
}
Run Code Online (Sandbox Code Playgroud)
但是当我转到mysiteurl.com/services/vps它时会显示404页。
(mysiteurl.com/services/1有效,但我不想在URL中使用id列)
默认情况下,sequelize 将在连接表中为多对多关系创建createdAt 和updatedAt 列,但我只想使用createdAt列并在创建行时自动设置它。
定制UserJob型号:
const UserJob = sequelize.define('UserJob', {
createdAt: DataTypes.DATE
}, {
timestamps: false
});
UserJob.beforeCreate((userJob, options) => {
console.log('before create');
userJob.createdAt = new Date();
});
return UserJob;
Run Code Online (Sandbox Code Playgroud)
协会:
User.belongsToMany(models.Job, {through: UserJob, foreignKey: 'user_id'});
Job.belongsToMany(models.User, {through: UserJob, foreignKey: 'job_id'});
Run Code Online (Sandbox Code Playgroud)
它没有设置createdAt,我该怎么办?
我正在发送InlineQueryResultArticle给客户,我想知道如何获得选定的结果及其数据(如 result_id,...)。
这是发送结果的代码:
token = 'Bot token'
bot = telegram.Bot(token)
updater = Updater(token)
dispatcher = updater.dispatcher
def get_inline_results(bot, update):
query = update.inline_query.query
results = list()
results.append(InlineQueryResultArticle(id='1000',
title="Book 1",
description='Description of this book, author ...',
thumb_url='https://fakeimg.pl/100/?text=book%201',
input_message_content=InputTextMessageContent(
'chosen book:')))
results.append(InlineQueryResultArticle(id='1001',
title="Book 2",
description='Description of the book, author...',
thumb_url='https://fakeimg.pl/300/?text=book%202',
input_message_content=InputTextMessageContent(
'chosen book:')
))
update.inline_query.answer(results)
inline_query_handler = InlineQueryHandler(get_inline_results)
dispatcher.add_handler(inline_query_handler)
Run Code Online (Sandbox Code Playgroud)
我正在寻找一种方法on_inline_chosen(data)来获取所选项目的 id。(1000 or 1001对于上面的代码段),然后向用户发送适当的响应。
我正在尝试在类方法中设置关联,但无法正常工作!
const User = sequelize.define('User', {
email: DataTypes.STRING,
password: DataTypes.STRING,
}, {
classMethods: {
associate: (models) => {
User.hasMany(models.AnotherModel, {foreignKey: 'userId'});
},
}
});
Run Code Online (Sandbox Code Playgroud)
但是当我在classMethods块外设置关联时,它可以工作:
User.associate = function (models) {
User.hasMany(models.AnotherModel, {foreignKey: 'userId'});
};
Run Code Online (Sandbox Code Playgroud)
为什么里面的代码classMethods块不起作用?
续集版本:4.2.0
我正在寻找一种仅更新jsonb列内嵌套键/值的方法。
这是User模型:
const User= sequelize.define('User', {
id: DataTypes.INTEGER,
name:DataTypes.STRING,
// other fields
data: DataTypes.JSONB
});
Run Code Online (Sandbox Code Playgroud)
当前data列值:
{
'email':{'verified':false,'token':'random token'},
'phone:{'verified':true}
}
Run Code Online (Sandbox Code Playgroud)
我想将email.verified属性更新为true使用单个 update查询。
我尝试了以下代码:
models.User.update({'data.email.verified':true},
{where:{id:1}}).then()...
models.User.update({data:{email:{verified:true}}},
{where:{id:1}}).then()...
Run Code Online (Sandbox Code Playgroud)
更新的列将是:
{
'email':{'verified':true},
}
Run Code Online (Sandbox Code Playgroud)
我也试过这个:
models.User.findById(1).then(user => {
user.set('data.email.verified', true);
user.save().then()...
});
Run Code Online (Sandbox Code Playgroud)
这有效,但我不想执行两个查询(选择然后更新)仅更新一个字段。
是否可以通过sequelize单个更新查询来执行此操作?
如何在 IntelliJ IDEA/Webstorm 中向edge.js模板文件添加语法高亮?
没有明显的插件可用。也许有类似的模板引擎可以工作?
node.js ×3
sequelize.js ×3
android ×1
edge.js ×1
jsonb ×1
laravel ×1
nestjs ×1
telegram-bot ×1
typescript ×1