<c-list-item type="context" title="车型:">{{item.model}}</c-list-item> <c-list-item type="context" title="零件名称:">{{item.partName}}</c-list-item> <c-list-item type="context" title="模具ID号:">{{item.dieNumber}}</c-list-item> <c-list-item type="context" title="程序号:">{{item.programNumber}}</c-list-item>如何将后两行数据接在前两行数据后面
时间: 2023-09-13 20:12:37 浏览: 118
你可以使用 HTML 的 `<br>` 标签将每个 `<c-list-item>` 标签的内容分行显示,代码如下:
```
<c-list-item type="context" title="车型:">{{item.model}}</c-list-item><br>
<c-list-item type="context" title="零件名称:">{{item.partName}}</c-list-item><br>
<c-list-item type="context" title="模具ID号:">{{item.dieNumber}}</c-list-item><br>
<c-list-item type="context" title="程序号:">{{item.programNumber}}</c-list-item>
```
这样,每个 `<c-list-item>` 标签的内容就会单独显示一行,并且后两行数据就会接在前两行数据的下方。
相关问题
我要用Intent实现跳转,应该把代码加在哪?package com.example.afinal import android.content.Intent import android.view.View import android.view.ViewGroup import android.widget.ImageView import android.widget.TextView import androidx.recyclerview.widget.RecyclerView import android.view.LayoutInflater import android.widget.Toast class ContextAdapter(val contextList: List<ContextModel>) : RecyclerView.Adapter<ContextAdapter.ViewHolder>() { inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { val contextCover: ImageView = view.findViewById(R.id.contextCover) val contextTitle: TextView = view.findViewById(R.id.contextTitle) } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { val view = LayoutInflater.from(parent.context).inflate(R.layout.home_context, parent, false) val viewHolder = ViewHolder(view) viewHolder.itemView.setOnClickListener { val position = viewHolder.adapterPosition val conetext = contextList[position] Toast.makeText(parent.context, "you clicked view ${conetext.title}", Toast.LENGTH_SHORT).show() } viewHolder.contextCover.setOnClickListener { val position = viewHolder.adapterPosition val context = contextList[position] Toast.makeText(parent.context, "you clicked image ${context.title}", Toast.LENGTH_SHORT).show() } return viewHolder } override fun onBindViewHolder(holder: ViewHolder, position: Int) { val context = contextList[position] holder.contextCover.setImageResource(context.coverUrl) holder.contextTitle.text = context.title holder.itemView.setOnClickListener { intent=Intent(this,DetailsActivity::class.java) } } override fun getItemCount() = contextList.size }
将跳转代码加在 onBindViewHolder 方法中。具体地,在 holder.itemView.setOnClickListener {} 中添加跳转代码,如下所示:
holder.itemView.setOnClickListener {
val intent = Intent(holder.itemView.context, DetailsActivity::class.java)
holder.itemView.context.startActivity(intent)
}
这样当用户点击某个列表项时,就会启动名为 "DetailsActivity" 的 Activity。记得事先在 AndroidManifest.xml 文件中声明这个 Activity。
def delete_selected(modeladmin, request, queryset): """ Default action which deletes the selected objects. This action first displays a confirmation page which shows all the deletable objects, or, if the user has no permission one of the related childs (foreignkeys), a "permission denied" message. Next, it deletes all selected objects and redirects back to the change list. """ opts = modeladmin.model._meta app_label = opts.app_label # Check that the user has delete permission for the actual model if not modeladmin.has_delete_permission(request): raise PermissionDenied using = router.db_for_write(modeladmin.model) # Populate deletable_objects, a data structure of all related objects that # will also be deleted. deletable_objects, model_count, perms_needed, protected = get_deleted_objects( queryset, opts, request.user, modeladmin.admin_site, using) # The user has already confirmed the deletion. # Do the deletion and return a None to display the change list view again. if request.POST.get('post') and not protected: if perms_needed: raise PermissionDenied n = queryset.count() if n: for obj in queryset: obj_display = force_text(obj) modeladmin.log_deletion(request, obj, obj_display) queryset.delete() modeladmin.message_user(request, _("Successfully deleted %(count)d %(items)s.") % { "count": n, "items": model_ngettext(modeladmin.opts, n) }, messages.SUCCESS) # Return None to display the change list page again. return None if len(queryset) == 1: objects_name = force_text(opts.verbose_name) else: objects_name = force_text(opts.verbose_name_plural) if perms_needed or protected: title = _("Cannot delete %(name)s") % {"name": objects_name} else: title = _("Are you sure?") context = dict( modeladmin.admin_site.each_context(request), title=title, objects_name=objects_name, deletable_objects=[deletable_objects], model_count=dict(model_count).items(), queryset=queryset, perms_lacking=perms_needed, protected=protected, opts=opts, action_checkbox_name=helpers.ACTION_CHECKBOX_NAME, media=modeladmin.media, ) request.current_app = modeladmin.admin_site.name # Display the confirmation page return TemplateResponse(request, modeladmin.delete_selected_confirmation_template or [ "admin/%s/%s/delete_selected_confirmation.html" % (app_label, opts.model_name), "admin/%s/delete_selected_confirmation.html" % app_label, "admin/delete_selected_confirmation.html" ], context) delete_selected.short_description = ugettext_lazy("Delete selected %(verbose_name_plural)s")
这段代码定义了一个默认的 Django Admin 后台操作,用于批量删除选中的对象。具体来说,这个操作会首先显示一个确认页面,列出所有将被删除的对象,以及与这些对象相关的其他对象(例如外键关联的对象)。如果用户没有删除权限,或者某些对象受到保护,则会显示一个“无权删除”或“不能删除”的消息。如果用户确认删除操作,则会删除所有选中的对象,并重定向到对象列表页面。
在代码中,`delete_selected()` 函数接受三个参数:`modeladmin` 表示 Django admin 后台的管理器对象,`request` 表示当前的 HTTP 请求对象,`queryset` 表示选中的对象的 QuerySet。函数首先获取模型的元数据信息,然后检查当前用户是否有删除权限。如果没有权限,则会引发 `PermissionDenied` 异常。接下来,函数调用 `get_deleted_objects()` 方法获取所有将被删除的对象及相关对象的信息,并根据用户的选择执行删除操作或者显示确认页面。最后,函数返回一个 `TemplateResponse` 对象,用于显示确认页面或者执行删除操作后的重定向。此外,函数还定义了一个 `short_description` 属性,用于在 Django admin 后台中显示操作名称。
阅读全文