【发布时间】:2021-12-03 07:25:54
【问题描述】:
目标:关于焦点事件我想自动填充 html 输入字段#City #State(全名)#State2(缩写)
问题
1) 如何将输入传递给函数?
2) 我需要做什么来填充字段?
在资源中\ 视图:locale.blade.php
<div>
<input type="text" name="City" id="City" value="{{ $city }}">
<input type="text" name="State" id="State" value="{{ $state }}">
<input type="text" name="State2" id="State2" value="{{ $state2 }}">
<input type="text" name="Zip" id="Zip" value="{{ $zip }}"
wire:focusout="setlocale">
</div>
在 App\Http\ LiveWire Locale.php
namespace App\Http\Livewire;
use Livewire\Component;
use App\Models\State;
use Illuminate\Support\Arr;
class Locale extends Component
{
public $zip = "";
public $city = "";
public $state = "";
public $state2 = "";
public function setlocale()
{
$locale_arr=[];
$g = $this->zip;
dd($g); ################## its only returning "" in my dd(); ###################
$z = State::get()->where('zip',$g);
$city = $z->city;
$state = $z->state_name;
$state2 = $z->state2_id;
//TODO somehow render these variables in input fields.
}
public function render()
{
return view('livewire.locale');
}
}
在 App\Models\ ** 状态**
class State extends Model
{
use HasFactory;
}
修补匠
>>> use App\Models\State
>>> $a = State::get()->where('zip','10001');
=> Illuminate\Database\Eloquent\Collection {#70820
all: [
2569 => App\Models\State {#35131
id: 2570,
zip: "10001",
lat: 40.7506,
lng: -73.9972,
city: "New York",
state_id: "NY",
state_name: "New York",
county_name: null,
timezone: null,
},
],
}
【问题讨论】:
-
@MichaelMano 请原谅我的无知是 vuejs 的一部分吗?
标签: php laravel laravel-livewire