搜索 - SO中文参考 - www.soinside.com (2024)

找到相关结果约 7362 条

Laravel POST 方法返回状态:405 不允许在 POST 方法上使用方法

请查找以下信息:NoteController.php 请查找以下信息:NoteController.php<?phpnamespace App\Http\Controllers;use App\Http\Requests\NoteRequest;use App\Models\Note;use Illuminate\Http\JsonResponse;class NoteController extends Controller{ public function index():JsonResponse { $notes = Note::all(); return response()->json($notes, 200); } public function store(NoteRequest $request):JsonResponse { $note = Note::create( $request->all() ); return response()->json([ 'success' => true, 'data' => $note ], 201); } public function show($id):JsonResponse { $note = Note::find($id); return response()->json($note, 200); } public function update(NoteRequest $request, $id):JsonResponse { $note = Note::find($id); $note->update($request->all()); return response()->json([ 'success' => true, 'data' => $note, ], 200); } public function destroy($id):JsonResponse { Note::find($id)->delete(); return response()->json([ 'success' => true ], 200); }}NoteRequest.php<?phpnamespace App\Http\Requests;use Illuminate\Foundation\Http\FormRequest;class NoteRequest extends FormRequest{ public function authorize() { return true; } public function rules() { return [ 'title', 'required|max:255|min:3', 'content', 'nullable|max:255|min:10', ]; }}Note.php(模型)<?phpnamespace App\Models;use Illuminate\Database\Eloquent\Factories\HasFactory;use Illuminate\Database\Eloquent\Model;class Note extends Model{ use HasFactory; protected $guarded = [];}api.php<?phpuse App\Http\Controllers\NoteController;use Illuminate\Support\Facades\Route;Route::prefix('v1')->group(function () { Route::resource('/note', NoteController::class);});php artisan 路线:列表GET|HEAD / ...................................................................................................................... POST _ignition/execute-solution ............... ignition.executeSolution › Spatie\LaravelIgnition › ExecuteSolutionController GET|HEAD _ignition/health-check ........................... ignition.healthCheck › Spatie\LaravelIgnition › HealthCheckController POST _ignition/update-config ........................ ignition.updateConfig › Spatie\LaravelIgnition › UpdateConfigController GET|HEAD api/v1/note .......................................................................... note.index › NoteController@index POST api/v1/note .......................................................................... note.store › NoteController@store GET|HEAD api/v1/note/create ................................................................. note.create › NoteController@create GET|HEAD api/v1/note/{note} ..................................................................... note.show › NoteController@show PUT|PATCH api/v1/note/{note} ................................................................. note.update › NoteController@update DELETE api/v1/note/{note} ............................................................... note.destroy › NoteController@destroy GET|HEAD api/v1/note/{note}/edit ................................................................ note.edit › NoteController@edit GET|HEAD sanctum/csrf-cookie .................................. sanctum.csrf-cookie › Laravel\Sanctum › CsrfCookieController@show迅雷请求(同邮递员)JSON 请求{ "title": "Hello World", "content": "Lorem ipsum."}尝试发出 JSON POST 请求并获取状态:405 方法不允许并且我正在使用 php artisan 服务,如果需要,我可以提供 GIT 项目。请告诉我。 您的验证规则看起来不正确。在您的 NoteRequest 类中,规则应该是一个关联数组,其中键是字段名称,值是验证规则。但是,在您的代码中,规则被定义为以逗号分隔的字符串列表。这可能会导致验证失败并返回 405 Method Not allowed 错误。public function rules(){ return [ 'title' => 'required|max:255|min:3', 'content' => 'nullable|max:255|min:10', ];}

如何查找给定的键是否存在于 std::map 中

我正在尝试检查给定的键是否在地图中,但有些无法做到:typedef 映射::迭代器 mi;地图米;m.insert(make_pair("f","++--"));一对 我正在尝试检查给定的键是否在地图中,但有些做不到:typedef map<string,string>::iterator mi;map<string, string> m;m.insert(make_pair("f","++--"));pair<mi,mi> p = m.equal_range("f");//I'm not sure if equal_range does what I wantcout << p.first;//I'm getting error here那么我怎样才能打印p中的内容呢? 使用 map::find 和 map::end:if (m.find("f") == m.end()) { // not found} else { // found} 要检查映射中是否存在特定键,请通过以下方式之一使用 count 成员函数:m.count(key) > 0m.count(key) == 1m.count(key) != 0map::find的文档说:“另一个成员函数map::count可用于仅检查特定键是否存在。”map::count的文档说:“因为地图容器中的所有元素都是唯一的,所以该函数只能返回1(如果找到该元素)或零(否则)。”要通过您知道存在的键从映射中检索值,请使用 map::at:value = m.at(key)与 map::operator[] 不同,如果指定的键不存在,map::at 不会在映射中创建新键。 C++20 为我们提供了 std::map::contains 来做到这一点。#include <iostream>#include <string>#include <map>int main(){ std::map<int, std::string> example = {{1, "One"}, {2, "Two"}, {3, "Three"}, {42, "Don\'t Panic!!!"}}; if(example.contains(42)) { std::cout << "Found\n"; } else { std::cout << "Not found\n"; }} 您可以使用.find():map<string,string>::iterator i = m.find("f");if (i == m.end()) { /* Not found */ }else { /* Found, i->first is f, i->second is ++-- */ } C++17 通过带有初始化器的 If 语句进一步简化了这一点。这样你就可以鱼与熊掌兼得了。if ( auto it{ m.find( "key" ) }; it != std::end( m ) ) { // Use `structured binding` to get the key // and value. const auto&[ key, value ] { *it }; // Grab either the key or value stored in the pair. // The key is stored in the 'first' variable and // the 'value' is stored in the second. const auto& mkey{ it->first }; const auto& mvalue{ it->second }; // That or just grab the entire pair pointed // to by the iterator. const auto& pair{ *it };} else { // Key was not found..} m.find == m.end() // not found 如果您想使用其他API,请找到m.count(c)>0 if (m.count("f")>0) cout << " is an element of m.\n"; else cout << " is not an element of m.\n"; 我想你想要map::find。如果 m.find("f") 等于 m.end(),则未找到密钥。否则,find 返回一个指向找到的元素的迭代器。错误是因为p.first是一个迭代器,它不适用于流插入。将最后一行更改为 cout << (p.first)->first;。 p 是一对迭代器,p.first 是迭代器,p.first->first 是键字符串。一张地图对于给定的键只能有一个元素,所以 equal_range 不是很有用。它是为映射定义的,因为它是为所有关联容器定义的,但它对于多重映射更有趣。 template <typename T, typename Key>bool key_exists(const T& container, const Key& key){ return (container.find(key) != std::end(container));}当然,如果你想变得更奇特,你可以随时模板化一个函数,该函数也采用已找到的函数和未找到的函数,如下所示:template <typename T, typename Key, typename FoundFunction, typename NotFoundFunction>void find_and_execute(const T& container, const Key& key, FoundFunction found_function, NotFoundFunction not_found_function){ auto& it = container.find(key); if (it != std::end(container)) { found_function(key, it->second); } else { not_found_function(key); }}并像这样使用它: std::map<int, int> some_map; find_and_execute(some_map, 1, [](int key, int value){ std::cout << "key " << key << " found, value: " << value << std::endl; }, [](int key){ std::cout << "key " << key << " not found" << std::endl; });这样做的缺点是想出一个好名字,“find_and_execute”很尴尬,我想不出更好的名字...... map<string, string> m;检查 key 是否存在,并返回出现次数(map 中为 0/1):int num = m.count("f"); if (num>0) { //found } else { // not found }检查key是否存在,并返回迭代器:map<string,string>::iterator mi = m.find("f"); if(mi != m.end()) { //found //do something to mi. } else { // not found } 在你的问题中,由坏的operator<<过载引起的错误,因为p.first是map<string, string>,你无法打印出来。尝试这个:if(p.first != p.second) { cout << p.first->first << " " << p.first->second << endl;} 小心地将查找结果与地图“m”的结尾进行比较,因为所有答案都有上面完成 地图::迭代器 i = m.find("f"); if (i == m.end()) { } else { } 您不应该尝试执行任何操作,例如如果迭代器 i 等于 m.end() 则打印键或值,否则会导致分段错误。 比较 std::map::find 和 std::map::count 的代码,我认为第一个可能会产生一些性能优势:const_iterator find(const key_type& _Keyval) const { // find an element in nonmutable sequence that matches _Keyval const_iterator _Where = lower_bound(_Keyval); // Here one looks only for lower bound return (_Where == end() || _DEBUG_LT_PRED(this->_Getcomp(), _Keyval, this->_Key(_Where._Mynode())) ? end() : _Where); }size_type count(const key_type& _Keyval) const { // count all elements that match _Keyval _Paircc _Ans = equal_range(_Keyval); // Here both lower and upper bounds are to be found, which is presumably slower. size_type _Num = 0; _Distance(_Ans.first, _Ans.second, _Num); return (_Num); } find() 和 contains() 都可以使用。根据文档。两种方法平均时间为常数,最坏情况下为线性时间。 我知道这个问题已经有一些很好的答案,但我认为我的解决方案值得分享。它适用于 std::map 和 std::vector<std::pair<T, U>>,并且可从 C++11 开始使用。template <typename ForwardIterator, typename Key>bool contains_key(ForwardIterator first, ForwardIterator last, Key const key) { using ValueType = typename std::iterator_traits<ForwardIterator>::value_type; auto search_result = std::find_if( first, last, [&key](ValueType const& item) { return item.first == key; } ); if (search_result == last) { return false; } else { return true; }} map <int , char>::iterator itr; for(itr = MyMap.begin() ; itr!= MyMap.end() ; itr++) { if (itr->second == 'c') { cout<<itr->first<<endl; } } 如果你想比较成对的地图,你可以使用这个方法:typedef map<double, double> TestMap;TestMap testMap;pair<map<double,double>::iterator,bool> controlMapValues;controlMapValues= testMap.insert(std::pair<double,double>(x,y));if (controlMapValues.second == false ){ TestMap::iterator it; it = testMap.find(x); if (it->second == y) { cout<<"Given value is already exist in Map"<<endl; }}这是一项有用的技术。

AWS Amplify #current-cloud-backend 重复文件

在我的AWS amplify项目中,包含已签出环境资源的当前云状态的#current-cloud-backend文件夹继续添加重复文件,例如backend-config 2....

Laravel 动态扩展或使用 Traits

可以在运行时扩展或使用不同的类吗?例子:假设我们有一个名为 Player 的模型(我们的 A 模型) 可以在运行时扩展或使用不同的类吗?示例:假设我们有一个 model 称为 Player(我们的 A 模型)<?phpnamespace App\Models;use Illuminate\Database\Eloquent\Model;class Player extends Model{}我们还有另外 2 个型号(B 和 C 型号)<?phpnamespace App\Models;use Illuminate\Database\Eloquent\Model;protected $connection= 'db_b';class PlayerInfoB extends Model{ function getName(){ return $this->name; }}我们的C型号<?phpnamespace App\Models;use Illuminate\Database\Eloquent\Model;protected $connection= 'db_c';class PlayerInfoC extends Model{ function getName(){ return $this->name_g; }}模型A (Player)如何在运行时根据配置或其他数据扩展Model B or C为什么我需要这个。我有 2 个或更多不同的表,这些表的列有不同的名称,例如:Table 1 - nameTable 2 - name_gTable 3 - name_full所以我需要一个可以随时调用的包装器getName(),而无需检查现在使用的表。$player = Player::get();echo $player->getName();如果有不清楚的地方,请评论,我会更新我的问题。更新基于madalin-ivascu答案可以这样完成吗?class Player extends Model{ protected $model; public function __construct(){ $this->setModel(); parent::__construct(); } protected function setModel(){ $this->model = $this->column_model_name } function getAttributeName(){ return $this->model->getName(); }} 如果不使用 eval 或 dirty hacks,就不可能在运行时编写一个类。您必须重新考虑您的类设计,因为您不太可能需要通过良好的设计来做到这一点。您可以做的是使用方法 setTable 和 on: 在运行时更改模型实例上的表和数据库连接Player::on('db_b')->setTable('player_info_b')->find($id);另一种方法(首选)是定义模型 PlayerInfoC 和 PlayerInfoB 来扩展您的 Player 模型,然后根据您的情况在需要时实例化类 B 或 C。 在您的代码中,您的脚本必须具有您检查的状态,以便知道何时使用正确的模型?既然如此,为什么不在 get name 中使用参数呢?class Player extends Model{ function getName($field){ return isset($this->{$field}) ? $this->{$field} : null; }}如果你经常这样做,那么使用魔法方法:class Player extends Model{ function __get($key){ return isset($this->{$field}) ? $this->{$field} : null; }}...echo $myModelInstance->{$field};http://php.net/manual/en/language.oop5.overloading.php#object.get在 Laravel 中,当你通过集合方法拉回数据时,它无论如何都会执行这个神奇的方法,因为所有属性都存储在称为属性的嵌套对象中,因此 __set() 和 __get() 看起来像这样:function __get($key){ return isset($this->attributes->{$key}) ? $this->attributes->{$key} : null;}function __set($key, $value){ return $this->attributes->{$key} = $value;}建议后者带有属性子集,这样可以防止数据与返回的数据库列名称与模型中已使用的名称发生冲突。这样,您只需在创建的每个模型中将一个属性名称作为保留名称进行管理,而不必担心您使用的数百个 var 名称会覆盖模型或模型扩展中的另一个属性名称。 使用该模型值来调用函数$player = Player::get();echo Player::getName($player->id,'PlayerInfoC');在 Player 模型中您只需调用public static function getName($id,$class) return $class::where('player_id',$id)->getName();//each class will have the function}ps:您需要进行一些验证来测试该名称是否存在另一种选择是在模型之间创建关系 您可以在模型中使用与以下相同的启动方法来执行此操作:protected static function booted(){ if (<--your condition-- >) { $traitInitializers[static::class][] = 'boot' . ExampleTrait::class; $traitInitializers[static::class][] = 'boot' . Organizations::class; }}

$or 来自 mongoose 的运算符在与 find() 方法一起使用时未提供所有必要的数据

我使用 find 方法和 $or 运算符来检查数据库中是否存在此行中任何现有的重复数据 const duplice = wait NewItemsData.find({ $or: newItems });检查...

使用 Azure Function 运行时和 pytest 'ModuleNotFoundError:没有名为...的模块'时出现导入问题

我的项目结构如下所示:回购/ |--模型/api |--function/function_app.py |--函数/工具.py |--函数/__init__.py |--测试/test_function_app.py...

Kafka Java Consumer Client 是单线程的吗

我们正在开始使用 Kafka,在阅读本文时 - https://docs.confluence.io/kafka-clients/java/current/overview.html - 它似乎暗示客户端是单线程的。*由于这个...

Javascript 函数 openFullscreen() ,如何让它在页面上的多个 iframe 上工作

在页面上我有一个 iframe,src 中有 *.pdf 文件。 <p>在页面上我有一个 iframe,src 中有 *.pdf 文件。</p><pre><code>&lt;div class=&#34;node--view-mode-full&#34;&gt;&lt;p&gt;&lt;iframe allow=&#34;fullscreen&#34; allowfullscreen=&#34;&#34; frameborder=&#34;0&#34; height=&#34;980&#34; scrolling=&#34;no&#34; src=&#34;https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf&#34; width=&#34;660&#34;&gt;&lt;/iframe&gt;&lt;/p&gt;&lt;p&gt;&lt;iframe allow=&#34;fullscreen&#34; allowfullscreen=&#34;&#34; frameborder=&#34;0&#34; height=&#34;980&#34; scrolling=&#34;no&#34; src=&#34;https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf&#34; width=&#34;660&#34;&gt;&lt;/iframe&gt;&lt;/p&gt;&lt;/div&gt;</code></pre><p>浏览器中内置的 pdf 查看器现在不支持 iframe 中的全屏模式。</p><p>我找到了解决方案<a href="https://www.w3schools.com/howto/howto_js_fullscreen.asp" rel="nofollow noreferrer">https://www.w3schools.com/howto/howto_js_fullscreen.asp</a>,解决了问题 - 以全屏模式打开 iframe。在 w3schools 的示例中,打开 iframe 的按钮已存在于 HTML <a href="https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_fullscreen" rel="nofollow noreferrer">https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_fullscreen</a>.</p><p>在我的解决方案中,我通过 javascript 添加按钮,因为带有 iframe 的页面已经存在,但没有此类按钮:</p><pre><code>jQuery(document).ready(function($){ $(&#34;.node--view-mode-full iframe[src*=&#39;.pdf&#39;]&#34;).each(function (index) { $(this).addClass(&#39;fullscreenframe&#39;); $(this).attr(&#39;id&#39;, &#39;fullscreen-&#39;+index); $(&#39;&lt;button onclick=&#34;openFullscreen()&#34;&gt;Open in Fullscreen Mode&lt;/button&gt;&amp;nbsp;&lt;strong&gt;Tip:&lt;/strong&gt; Press the &#34;Esc&#34; key to exit full screen.&lt;br&gt;&#39;).insertBefore(this); });});</code></pre><p>然后添加一个全屏打开 iframe 的功能(与 w3schools 相同):</p><pre><code>function openFullscreen() { var elem = document.getElementsByClassName(&#34;fullscreenframe&#34;)[0]; if (elem.requestFullscreen) { elem.requestFullscreen(); } else if (elem.webkitRequestFullscreen) { /* Safari */ elem.webkitRequestFullscreen(); } else if (elem.msRequestFullscreen) { /* IE11 */ elem.msRequestFullscreen(); }};</code></pre><p>当页面上只有一个带有 *.pdf 的 iframe 时,Everysing 工作正常。但是,当我在页面上有两个或多个 iframe,并且单击任何 iframe 附近的“以全屏模式打开”任何按钮时,我总是在全屏模式下只看到第一个 *.pdf...</p><p>我知道,这是因为我只得到 elem = document.getElementsByClassName("fullscreenframe")[0]; 中的第一个 iframe;</p><p>我知道我需要使用类似的每个或类似的东西,但我无法解决它。在搜索关于页面上一个全屏元素的所有解决方案时,没有关于页面上多个元素的解决方案...谢谢。</p> </question><answer tick="true" vote="0"><p>也许是这样的:</p><pre><code>jQuery(document).ready(function($){ $(&#34;.node--view-mode-full iframe[src*=&#39;.pdf&#39;]&#34;).each(function (index) { $(this).addClass(&#39;fullscreenframe&#39;); $(this).attr(&#39;id&#39;, &#39;fullscreen-&#39;+index); $(&#39;&lt;button onclick=&#34;openFullscreen(&#39; + index + &#39;)&#34;&gt;Open in Fullscreen Mode&lt;/button&gt;&amp;nbsp;&lt;strong&gt;Tip:&lt;/strong&gt; Press the &#34;Esc&#34; key to exit full screen.&lt;br&gt;&#39;).insertBefore(this); });});function openFullscreen(index) { var elem = document.getElementsByClassName(&#34;fullscreenframe&#34;)[index]; if (elem.requestFullscreen) { elem.requestFullscreen(); } else if (elem.webkitRequestFullscreen) { /* Safari */ elem.webkitRequestFullscreen(); } else if (elem.msRequestFullscreen) { /* IE11 */ elem.msRequestFullscreen(); }}</code></pre> </answer><answer tick="false" vote="0"><p>为什么不整合 jQuery?</p><pre><code>const fullScreen = element =&gt; element.requestFullScreen(); // all modern browsers$(function(){ $(&#34;.node--view-mode-full iframe[src*=&#39;.pdf&#39;]&#34;).each(function (index) { $(this).addClass(&#39;fullscreenframe&#39;); $(this).attr(&#39;id&#39;, &#39;fullscreen-&#39;+index); $(&#39;&lt;button class=&#34;fullScreen&#34;&gt;Open in Fullscreen Mode&lt;/button&gt;&amp;nbsp;&lt;strong&gt;Tip:&lt;/strong&gt; Press the &#34;Esc&#34; key to exit full screen.&lt;br&gt;&#39;).insertBefore(this); }); $(&#34;.fullScreen&#34;).on(&#34;click&#34;, function() { const $iFrame = $(this).closest(&#39;p&#39;).find(&#39;iframe.fullscreenframe&#39;); if ($iFrame) fullScreen($iFrame.get(0)); // pass the DOM element });});</code></pre> </answer></body></html>

修复 Flutter GitHub 项目导入错误:Dart SDK 版本和空安全兼容性

从github导入flutter中的任何项目时,它显示“sdk:'> = 2.7.0的下限<3.0.0'" must be 2.12.0' or higher to enable null safety. The current Dart SDK (3.2.3)...

如何使用预选值初始化下拉列表(<select/>)然后更改它?

我有一个网格,每行都有下拉菜单,我需要从数据库渲染它的状态。因此,我定义了与指定用于从数据库中预选择值的选定选项类似的下拉菜单。 我有一个网格,每一行都有下拉菜单,我需要从数据库渲染它的状态。因此,我定义了下拉列表,并指定了用于从数据库中预选择值的选定选项。<select id='selectId'><option value='1'>Option 1</option><option value='2' selected='selected'>Option 2</option><option value='3'>Option 3</option></select>​问题在于,当我更改浏览器中定义的下拉列表的值时,它会在 UI 上发生变化,但选定的属性不会移动并保持在原来的位置。因此,当我调用 $("#selectId").val() 时,我会得到旧的值。初始化下拉控件然后能够在浏览器中或通过 jQuery 自由更改其值的适当方法是什么? 这似乎工作正常(Ubuntu 上的 Firefox):HTML<select id='selectId'><option value='1'>Option 1</option><option value='2' selected='selected'>Option 2</option><option value='3'>Option 3</option></select>JS$('#selectId').change(function() { var opt = $(this).find('option:selected'); console.log([opt.val(), opt.text()]); });var opt_sel = $('#selectId option:selected');opt_sel.val(99);opt_sel.text('Changed option');如果您选择这些选项,您将看到它将打印更改后的版本。工作示例:http://jsfiddle.net/vm4Q8/希望这有帮助。 应该可以正常工作。可能是你设置不正确。您应该将选项的 value 传递给 val() 方法来选择它。例如 $('#selectId').val('1'); 会将第一个选项设置为选定状态,然后调用 $('#selectId').val() 将为您提供 1 而不是 2。这是工作示例http://jsfiddle.net/3eu85/ 可以获取选中选项的val,而不是select$('select#selectId option:selected').val(); 文档:http://api.jquery.com/val/ 您在哪个浏览器中尝试此操作?你的代码对我来说看起来很好,并且似乎可以在 this jsFiddle 中工作。 请使用此代码,$('#selectId option:selected').val(); <script> $(document).ready(function () { $('#ta_ingredient').val('2'); });</script>

在 JUnit 5 中,如何在所有测试之前运行代码

@BeforeAll 注释标记在类中的所有测试之前运行的方法。http://junit.org/junit5/docs/current/user-guide/#writing-tests-annotations但是有没有办法在...之前运行一些代码

javascript:如何中止 $.post()

我的post方法如下图:$(".buttons").click(function(){ var gettopic=$.post("topic.php", {id: topicId}, function(result){ // 处理返回结果的代码 });})我尝试...

如何将 '<p class="p1">' 、 '<div class="disp-quote-p">/following-sibling::*[1][self::p[@class='p1']]' 包装/分组在单个 'p' 元素中

我正在包装节点 ' 、 '' 和 div[@class='disp-quote-p']/following-sibling::*[1][self::p[@class=' p1']] 里面... 我正在尝试将节点 <p class="p1">' , '<div class="disp-quote-p">' and div[@class='disp-quote-p']/following-sibling::*[1][self::p[@class='p1']] 包裹在单个 p 元素中。输入 XML:-<root> <p class="p">aa</p> <p class="p1">Although:</p> <div class="disp-quote-p"> <p class="p">We had seen.</p> </div> <p class="p1">This dot.</p> <img src="a.png"/> <box>box</box> <p class="p">bb</p></root>我正在尝试将节点包装在单个 p 元素中的代码,但此节点 <p class="p1">This dot.</p> 与 <div class="disp-quote-p"> 节点一起包装。<xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="root"> <xsl:copy> <xsl:for-each-group select="*" group-starting-with="p[@class='p1']"> <xsl:for-each-group select="current-group()" group-adjacent="self::p[@class='p1'] or self::div[@class='disp-quote-p']"> <xsl:choose> <xsl:when test="self::p[@class='p1']"> <p><xsl:apply-templates select="node(), current-group() except ."/></p> </xsl:when> <xsl:otherwise> <xsl:copy-of select="current-group()"/> </xsl:otherwise> </xsl:choose> </xsl:for-each-group> </xsl:for-each-group> </xsl:copy> </xsl:template>网址链接:[http://xsltransform.net/eiov64R/1]预期输出:-<root> <p class="p">aa</p> <p>Although:<disp-quote><p class="p">We had seen.</p></disp-quote>This dot.</p> <img src="a.png"/> <box>box</box> <p class="p">bb</p></root> 试试这个: <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="root"> <xsl:copy> <xsl:for-each-group select="*" group-adjacent="if(self::p[@class='p1'] or self::div) then -1 else position()"> <xsl:choose> <xsl:when test="self::p[@class='p1'] or self::div"> <p><xsl:apply-templates select="current-group()"/></p> </xsl:when> <xsl:otherwise> <xsl:copy-of select="current-group()"/> </xsl:otherwise> </xsl:choose> </xsl:for-each-group> </xsl:copy> </xsl:template> <xsl:template match="p[@class='p1']"> <xsl:apply-templates/> </xsl:template> <xsl:template match="div[@class='disp-quote-p']"> <xsl:element name="disp-quote"> <xsl:apply-templates/> </xsl:element> </xsl:template>

从域中提取数据

主机 = 'unw.us.co'data1 = 主机.find('.')打印(数据1)data2 = host.find('.', data1)打印(数据2)数据3 = 主机[数据1+1 : 数据2 ]打印(数据3)我正在尝试提取本示例中的国家/地区代码...

Azure SWA - 未找到 Nextjs 图像

我正在尝试在 Azure 的静态 Web 应用程序服务上部署 Next JS 应用程序。我已经构建并运行了应用程序,但图像未渲染。从控制台,它报告 404 not find e...

使用 OSX 终端命令计算目录中的文件数量

我正在寻找返回数字的特定目录文件计数。我将其输入终端,它可以给我指定目录的文件计数。我已经尝试过 echo find "'dir...

Python 通配以匹配 find 的“-print -quit”行为

我有几个任意深度的目录,每个目录都包含一个具有一致名称的文件。在命令行中,我可以使用 find -name -print -quit 进行优化... 我有一些任意深度的目录,每个目录都包含一个具有一致名称的文件。在命令行中,我可以使用 find <dir> -name <filename> -print -quit 进行优化搜索:一旦找到文件,它就会停止查找目录。我可以做到这一点,因为它找到了我正在寻找的东西。我可以使用 glob (或者我想是 os.walk)来做同样的事情。但是,一旦找到我要查找的文件,这两个选项似乎都无法停止:无论如何,它们都会索引完整目录 - globbing 会查找尽可能多的匹配项,而 os.walk 只允许我索引完成后进行过滤。有没有办法在 Python 中获得优化的 find 行为,而不是在子进程中执行 find? 如果您使用 topdown=True 选项(默认),它不会首先生成整个层次结构;生成器一次返回一个目录。这允许您就地更改 os.walk() 值以防止其下降到某些子目录,并且还允许您尽早跳出循环。

Laravel 购物车页面,表单内有一个表单,用于处理删除和提交数据更新数据库

我有一个购物车页面,表格内有一个表格,也许你可以建议我应该做什么?根据图片,我给出的蓝色圆圈是一个表格我的刀片代码我有一个购物车页面,表格内有一个表格,也许你可以建议我应该做什么?根据图片我给出的蓝色圆圈是一个表格我的刀片代码<table class="table"><thead> <tr> <th scope="col">No</th> <th scope="col">Nama Barang</th> <th scope="col">Quantity</th> <th scope="col">Action</th></tr></thead><tbody>@php $no = 1; @endphp@forelse ($permintaans as $b)<tr><td>{{ $no ++ }}</td><td>{{ $b->nama_kategori }} {{ $b->nama_atk }}</td><td><form action="{{ route('permintaan.update', $b->id) }}" method="POST" style="display: inline-block;">@csrf@method('PUT')<div class="input-group input-group-sm mb-3"><input type="number" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-sm" name="satuan_permintaan" min="0" max={{ $b->stok }} required><span class="input-group-text" id="inputGroup-sizing-sm">{{ $b->subsatuan_atk }}</span></div> </td><td><form action="{{ route('permintaan.destroy', $b->id) }}" method="POST" style="display: inline-block;"> @csrf@method('DELETE')<button type="submit" class="btn custom2-btn"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="red" class="bi bi-trash" viewBox="0 0 16 16"><path d="M5.5 5.5A.5.5 0 0 1 6 6v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5m2.5 0a.5.5 0 0 1 .5.5v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5m3 .5a.5.5 0 0 0-1 0v6a.5.5 0 0 0 1 0z"/><path d="M14.5 3a1 1 0 0 1-1 1H13v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V4h-.5a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1H6a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1h3.5a1 1 0 0 1 1 1zM4.118 4 4 4.059V13a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V4.059L11.882 4zM2.5 3h11V2h-11z"/></svg></button></form></td></tr>@empty@endforelse</tbody></table>我的控制器public function store(Request $request) { $task = new Permintaan(); $task->atk_id = $request->input('atk_id'); $task->proses = 'Proses'; if (Permintaan::where('atk_id', $task->atk_id)->exists()){ return redirect('/atk/permintaan')->with(['info' => 'ATK Sudah Dalam Permintaan']); } else{ $task->save(); return redirect()->route('permintaan.index'); } } public function destroy($id) { $permintaan = Permintaan::find($id); $permintaan->delete(); return redirect()->route('permintaan.index'); }我要处理删除并提交数据更新数据库在开始销毁表单之前关闭更新表单第一个表单标签(缺少)。

Python 3.7 BeautifullSoup soup.find 错误 - find() 不接受关键字参数

我从 URL 获得了以下 HTML: 我从 URL 中获得了以下 HTML:<h4> \r\n \r\n\r\n <a href="/l"> \r\n <!-- mp_trans_rt_start id="1" args="as" 1 -->\r\n <span class="brandWrapTitle">\r\n <span class="productdescriptionbrand">Mxxx</span>\r\n </span>\r\n <span class="nameWrapTitle">\r\n <span class="productdescriptionname">Axxxname</span>\r\n </span>\r\n <!-- mp_trans_rt_end 1 -->\r\n </a> \r\n\r\n </h4>我正在尝试使用 python 来查找类名: import urllib.requestfrom bs4 import BeautifulSoupurl = "https://link"user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36'urlwithagent = urllib.request.Request(url,headers={'User-Agent': user_agent})response = urllib.request.urlopen(urlwithagent)soup = response.read()product = soup.find("h4", attrs ={"class=": "productdescriptionname"})print (product)Everythink 完美运行直到上线:product = soup.find("h4", attrs ={"class=": "productdescriptionname"})我收到如下错误:find() takes no keyword arguments我不知道如何解决它 - 有很多信息,但没有任何作用:/ 在使用 BeautifulSoup 之前,您需要将其转换为 find 对象,否则它会使用 str.find例如:soup = BeautifulSoup(response.read(), "html.parser")product = soup.find("h4", attrs ={"class": "productdescriptionname"})print (product) 我认为这值得一提,如果 find 方法有问题,检查 type(soup) 是一个很好的方法来查明您是否正在使用正确的 bs4.BeautifulSoup 对象而不是 str。我想在这里指出一件事,如果使用 soup.prettify() 使 html 可读。需要注意的是,.prettify() 将 bs4.BeautifulSoup 转换为 str。所以这应该单独使用,例如:soup = BeautifulSoup(response) # type(soup) --> bs4.BeautifulSoupprint(soup.prettify()) # print readable html不喜欢:soup = BeautifulSoup(response).prettify() # type(soup) --> str我在网上读到的关于这个问题的另一件事是这样的:“你的 beautiful soup 版本可能不支持 find。”因此,我最终升级和降级了版本很多次,然后才意识到这是一个错误的陈述由业余爱好者制作。在打印之前我已经为此奋斗了大约 45 分钟type(soup)。我希望这可以节省其他人的时间。 Может кому подойдет история такая повторял за автором ютуба и переписывал код для парсинга и вышла такая же ошибка как в вопросе искал читал, шерстил инет пока не начал перепроверять свой код в общем мой код с ошибкой:from requests import Sessionfrom bs4 import BeautifulSoup as BSfrom time import sleepheaders = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 YaBrowser/23.11.0.0 Safari/537.36'}work = Session()work.get('https://quotes.toscrape.com/', headers=headers)response = work.get('https://quotes.toscrape.com/login', headers=headers)soup = BS(response.text, 'lxml')token = soup.find('from').find('input').get('')в чем здесь ошибка? вот в этой строке token = soup.find('from').find('input').get('')а именно soup.find('from') я решил скать ошибку методом исключения поэтому довел до такого состояния и понял что в странице нет тэга '来自' а есть тэг '形式'как только поменял на тэг 'form' ошибка с soup.find() - find() ушламожет кому поможет

使用部分进行主动拆解/重新渲染不会重新渲染部分

这是小提琴(对警报感到抱歉)http://jsfiddle.net/PCcqJ/92/var ractive = new Ractive({ 模板:'#templateOne', 部分:{ aPartial:'哦,看,partia... 这是小提琴(抱歉有警报)http://jsfiddle.net/PCcqJ/92/var ractive = new Ractive({ template: '#templateOne', partials: { aPartial: '<div>Oh look, the partial is rendered!</div>' }});function cb() { alert('but now we unrender'); ractive.once('complete', function() { alert('we rendered again, and now you can\'t see the partial content'); }); ractive.render('container');}ractive.render('container');ractive.once('complete', function() { alert('so we render the first time, and you can see the partial'); ractive.unrender().then(cb); });此处的部分不会重新渲染。为什么是这样?部分仍在部分对象中,并且它们尚未渲染,那么什么会阻止它们再次渲染?这个小提琴会渲染、取消渲染,然后重新渲染,每次发生其中一种情况时都会向您发出警报。 我做了一个工作jsfiddle:https://jsfiddle.net/43gLqbku/1/<div id='container'></div><script id="templateOne" type="x-template"> {{>aPartial}}</script>var ractive = new Ractive({ el:"#container", template: '#templateOne', partials: { aPartial: '<div>Oh look, the partial is rendered!</div>' }});function cb() { alert('but now we unrender'); ractive.once('complete', function() { alert('we rendered again, and now you can\'t see the partial content'); }); ractive.render('container');}//ractive.partials.part = '<div>this is a partial</div>';ractive.once('complete', function() { alert('so we render the first time, and you can see the partial'); ractive.unrender().then(cb); });在调用render之前需要调用ractive.once('completed')你不需要 ractive.render("container");在活动代码下,因为它在第一次运行时自动呈现在你的jsfiddle中你导入的ractive不起作用你没有在 jsFiddle 活动代码中包含 el:"#container"

搜索 - SO中文参考 - www.soinside.com (2024)

References

Top Articles
Latest Posts
Article information

Author: Prof. Nancy Dach

Last Updated:

Views: 6569

Rating: 4.7 / 5 (77 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Prof. Nancy Dach

Birthday: 1993-08-23

Address: 569 Waelchi Ports, South Blainebury, LA 11589

Phone: +9958996486049

Job: Sales Manager

Hobby: Web surfing, Scuba diving, Mountaineering, Writing, Sailing, Dance, Blacksmithing

Introduction: My name is Prof. Nancy Dach, I am a lively, joyous, courageous, lovely, tender, charming, open person who loves writing and wants to share my knowledge and understanding with you.