在编辑任何输入时都会呈现数据列表形式?

如何解决在编辑任何输入时都会呈现数据列表形式?

使用livewire 1.3 / alpinejs 2.x.x,我使用过滤器文本列出数据 和选择输入,然后单击“搜索”按钮 单击“搜索”按钮。 但是当文本/选择输入失去焦点而没有单击“搜索”按钮时,将运行搜索。 我通过表单的wire:loading块和日志文件中的1行看到了它,这是我在render方法中触发的 那不是我所需要的:我只需要单击“搜索”按钮就可以运行渲染方法。 我尝试使用alpinejs,但失败了... 在组件app / Http / Livewire / Admin / AppNews.php中,我有:

<?php

namespace App\Http\Livewire\Admin;

use Carbon\Carbon;
use Livewire\Component;
use App\News;
use Livewire\WithPagination;
use Livewire\WithFileUploads;

class AppNews extends Component
{
    use WithPagination;
    use WithFileUploads;

    public $filters = [
        'title' => '','published' => '',];
    ];
    public $uploaded_file_name;
    public $uploadedImageFilenameData;
    public $uploadedNewsImage;
    protected $listeners = ['fileUpload' => 'handleFileUpload'];


    public $current_news_id;
    public $updateMode = 'browse';

    public function render()
    {
        \Log::info('-1 NewsRENDER $this->filters ::' . print_r($this->filters,true));
        $news_rows_count  = News
            ::getByTitle($this->filters['title'],true)
            ->getByPublished($this->filters['published'],true)
            ->count();
        $backend_per_page = Settings::getValue('backend_per_page',CheckValueType::cvtInteger,20);
        $this->emit('app_news_opened',['mode' => 'browse','id' => null]);

        $newsPublishedValueArray = SetArrayHeader([['key' => '','label' => ' -Select published- ']],News::getNewsPublishedValueArray(true));
        $newsDataRows = News
            ::getByTitle($this->filters['title'],true)
            ->with('creator')
            ->orderBy('news.created_at','desc')
            ->paginate($backend_per_page);

        $newsDataIds = [];
        foreach ($newsDataRows as $nextNews) {
            $newsDataIds[] = $nextNews->id;
        }

        return view('livewire.admin.app-news.container',[
            'newsDataRows'             => $newsDataRows,'newsDataIds'              => $newsDataIds,'form'                     => $this->form,'news_rows_count'          => $news_rows_count,'newsPublishedValueArray'  => $newsPublishedValueArray,]);
    }

并在模板resources / views / livewire / admin / app-news / container.blade.php中:

<article class="admin_page_container">


<div class="card form-admin-news">
    
    <div class="card-body card-block">
    
        <div class="spinner-border" role="status" wire:loading>
            <span class="sr-only">Loading...</span>
        </div>
    
        ...
            <fieldset class="bordered text-muted p-2 m-2" x-data="{ title: '{{$filters['title']}}',published: '{{$filters['published']}}',publishedItems: <?php print  str_replace('"',"'",json_encode( $newsPublishedValueArray) ) ?>   } ">
                <div> $filters::{{ var_dump($filters) }}</div>
                title::<div x-html="title"></div>
                published::<div x-html="published"></div>
                <legend class="bordered">Filters</legend>
                
                
                <dl class="block_2columns_md m-0 p-2">
                    <dt class="key_values_rows_label_13">
                        <label class="col-form-label" for="temp_filter_title">
                            By title
                        </label>
                    </dt>
                    <dd class="key_values_rows_value_13" >
                        <div class="content_with_right_button">
                            
                            <div
                                class="content_with_right_button_left_content"
                                wire:model.lazy="filters.title"
                            >
                                <input
                                    class="form-control admin_control_input"
                                    type="text"
                                    x-model="title"
                                    x-on:blur="$dispatch('input',title)"
                                    id="title"
                                >
                            </div>
                            <div class="content_with_right_button_right_button pl-2">
                                <button class="btn btn-outline-secondary nowrap_block" wire:click="makeSearch( )">
                                    {!! $viewFuncs->showAppIcon('filter') !!}Search
                                </button>
                            </div>
                        </div>
                    </dd>
                </dl>
                
                <dl class="block_2columns_md m-0 p-2">
                    <dt class="key_values_rows_label_13">
                        <label class="col-form-label" for="temp_filter_published">
                            By published
                        </label>
                    </dt>
                    <dd
                        class="key_values_rows_value_13"
                        wire:model.lazy="filters.published"
                    >
                        <select
                            x-model="published"
                            x-on:blur="$dispatch('select',published)"
                            id="published"
                            class="form-control editable_field admin_control_input"
                        >
                            <template x-for="nextPublishedItem in publishedItems">
                                <option :value="nextPublishedItem.key" x-text="nextPublishedItem.label"></option>
                            </template>
                        </select>
                        
                        @error('form.published')
                        <div class="validation_error">{{ clearValidationError($message,['form.'=>'']) }}</div> @enderror
                    </dd>
                </dl>
                
            </fieldset> <!-- Filters -->
        
        ...
        @endif {{-- @if($updateMode=='browse')--}}
        
    
        @endif {{-- @if($updateMode=='browse')--}}
            @if(count($newsDataRows) > 0)
                
                <div class="table-responsive table-wrapper-for-data-listing" x-data="selectedNewsIdsBoxXData()">
                    
                    <table>
                        ...
                    </table>
                </div> <!-- <div class="table-responsive table-wrapper-for-data-listing"> -->
            
            @endif {{-- @if(count($newsDataRows) > 0) --}}
        @endif {{-- @if($updateMode=='browse')  --}}
    </div> <!-- <div class="card-body card-block"> -->
    
    

</div> <!-- <div class="card"> -->
</article> <!-- page_content_container -->

哪种方法有效?

已修改的块2:

我尝试使用alpinejs2的另一种方式:在这种情况下,例如当组件的公共变量更改时,我尝试使用它: 单击“搜索”按钮时使用派发方法

<div class="card form-admin-facilities" x-data="adminFacilitiesComponent()">
    ...
    
    filter_name: {{$filter_name}}<br>
    ...
    temp_filter_name: <span x-html="temp_filter_name"></span><br>
    ...
    
    <fieldset class="bordered text-muted p-2 m-2">
        <legend class="bordered">Filters</legend>
        <div class="content_with_right_button" wire:model.lazy="filter_name">
            <div class="content_with_right_button_left_content" >
                <input
                    class="form-control admin_filter_input"
                    x-model="temp_filter_name"
                    
                    type="text"
                >
            </div>
            <div class="content_with_right_button_right_button pl-2" >
                <button class="btn btn-outline-secondary" @click="$dispatch('input',temp_filter_name)"  type="button">Search
                </button>
                <!-- In more complicated form can be several filter fields : text and select inputs -->
            </div>
        </div>
    
    </fieldset> <!-- Filters -->
    
    
    ...
    <script>
        function adminFacilitiesComponent() {
            return {
                temp_filter_name:'',

,并且在组件中,我定义了public $ filter_name var,该变量在渲染方法中使用:

   class Facilities extends Component
        {
            public $form= [
                'name'=>'','descr'=> '','created_at'=> '','is_reopen'       => false,];

            public $current_facility_id;
            public $filter_name= '';
            public $updateMode = 'browse';

            public function render()
        {
        \Log::info( '-1 render Facilities $this->filter_name ::' . print_r(  $this->filter_name,true  ) );
            $this->facility_rows_count = Facility
                ::getByName($this->filter_name,true)
        ->count();
            $backend_per_page = Settings::getValue('backend_per_page',20);

            return view('livewire.admin.facilities.container',[
                'facilityDataRows' => Facility
            ::orderBy('created_at','desc')
        ->getByName($this->filter_name,true)
        ->paginate($backend_per_page),'facility_rows_count'=> $this->facility_rows_count
        ]);
        }

但是它不符合我的预期:当输入失去焦点时,在文本输入中输入值 表单再次呈现。我希望仅当我单击“搜索”按钮时才能呈现表单 表格将以新输入的值呈现。我不将模糊事件用于文本输入, 不明白为什么此输入失去焦点时会呈现表单?

修改的块3: 使用x-ref =我这样做:

<div class="content_with_right_button" wire:model.lazy="filter_name">
    <div class="content_with_right_button_left_content" >
        <input
            class="form-control admin_filter_input"
            x-model="temp_filter_name"
            x-ref="searched"
            type="text"
        >       1111111
    </div>
    <div class="content_with_right_button_right_button pl-2" >
        <button class="btn btn-outline-secondary nowrap_block" wire:click="makeSearch(this.$refs.searched)" type="button">
            Search
        </button>
    </div>
</div>

但是点击搜索按钮时出现错误:

VM1983:6 Uncaught TypeError: Cannot read property 'searched' of undefined
    at eval (eval at parseOutMethodAndParams (directive.js:55),<anonymous>:6:27)
    at _default.parseOutMethodAndParams (directive.js:55)

看起来不可能使用this。$ refs。值

wire:click="makeSearch    .

我需要触发组件方法

public function makeSearch($search_value='')
{

并将输入的值发送到其中。 看来我尝试的方法无效。 如果有有效的方法?

谢谢!

解决方法

在修改后的块2中,应在AlpineJS组件的base div中使用wire:ignore。这将使livewire忽略该组件。

<div class="card form-admin-facilities" wire:ignore x-data="adminFacilitiesComponent()">

您的$dispatch()应该在单击按钮时处理设置值。

,

为了使livewire忽略该组件,只需在修改后的块2中向组件的div中添加wire:ignore,然后在dispatch方法中,您可以编写单击按钮后发生的逻辑。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-