[英]I have an array of objects. I need to remove the row which doesn't have a particular property
[英]I have no access to array, but need to remove commas
所以這是一個有點晦澀的。
我在 Wordpress 上使用 Formidable Forms Pro 來制作相當復雜的表格。 我使用動態字段(誰的選擇來自另一個表單的條目,因此是動態的),用戶可以在其中進行多項選擇。
然后我使用動態列表字段來更直觀地顯示用戶的選擇。
那個圖像看起來還不錯,不是最好的造型,但我試圖在讓它看起來漂亮之前先調整機制。
樣式已經到位,因為我隱藏了由 Formidable Forms 動態放入的逗號。 問題就在這里。
如果我希望列表出現在另一個之上,這種方法會很好用,但預計用戶在某些情況下可能想要進行 10 個或更多選擇,列表將開始占據過多的屏幕。
現在,有很多關於如何從字符串和數組中刪除分隔符的示例(我相信這是一個字符串數組,)但是,我無法訪問任何一個來創建變量以允許該過程發生。 保持原樣意味着我不能使用 CSS Grid 來設置列表樣式,因為我希望在有足夠空間時使用重復自動調整方法將它們並排對齊,因為逗號被認為是網格元素類似於列表元素。
檢查代碼表明沒有包含逗號的 html 元素,因此沒有希望在那里使用 Javascript 來刪除類中的逗號或其他任何內容。
如果任何知道如何為我指明正確方向的人都可能,將不勝感激。
由於我使用 Formidable Forms 來創建表單,因此我可以為您檢索的唯一代碼實際上是輸出,這就是我在圖像中提供的內容。 不理想,我知道。
我在 Formidable 中可以訪問的唯一預渲染代碼如下。 雖然我懷疑這對任何人都沒有用,這就是我最初沒有發布它的原因:
<div id="frm_field_[id]_container" class="frm_form_field form-field [required_class][error_class]">
<label for="field_[key]" id="field_[key]_label" class="frm_primary_label">[field_name]
<span class="frm_required">[required_label]</span>
</label>
<div class="frm_opt_container" aria-labelledby="field_[key]_label" role="group">[input]</div>
[if description]<div class="frm_description" id="frm_desc_field_[key]">[description]</div>[/if description]
[if error]<div class="frm_error" id="frm_error_field_[key]">[error]</div>[/if error]
</div>
和呈現的代碼:
<div id="frm_field_70_container" class="frm_form_field form-field frm_none_container frm_dynamic_data_container">
<label for="field_b0r85" id="field_b0r85_label" class="frm_primary_label">Dynamic
<span class="frm_required"></span>
</label>
<div class="frm_opt_container" aria-labelledby="field_b0r85_label" role="group" style=""><p class="frm_show_it"></p><div class="combined_field_output"><img src="http://3.11.173.147.xip.io/wp-content/uploads/formidable/2/IMG-20190512-WA0005-29-150x150.jpg" alt="Image of exercise 5545" style="width:60px;height:60px"><h3>5545</h3><p>Abdominals</p></div>, <div class="combined_field_output"><img src="http://3.11.173.147.xip.io/wp-content/uploads/formidable/2/IMG-20190512-WA0005-13-150x150.jpg" alt="Image of exercise goo" style="width:60px;height:60px"><h3>goo</h3><p>Abdominals</p></div>, <div class="combined_field_output"><img src="http://3.11.173.147.xip.io/wp-content/uploads/formidable/2/IMG-20190512-WA0005-27-150x150.jpg" alt="Image of exercise should work" style="width:60px;height:60px"><h3>should work</h3><p>Abdominals</p></div>, <div class="combined_field_output"><img src="http://3.11.173.147.xip.io/wp-content/uploads/formidable/2/IMG-20190512-WA0005-14-150x150.jpg" alt="Image of exercise Walking Lunges" style="width:60px;height:60px"><h3>Walking Lunges</h3><p>Abdominals</p></div><p></p>
腹部
,腹部
,腹部
,腹部
">編輯:強大的提供了一種自定義動態鏈接字段的方法, 該字段未提及任何分隔符。 我的理解是,如果未指定分隔符,則會動態添加逗號,這就是我認為這里正在發生的事情。 可以編輯此 PHP 鈎子以指定完全不添加分隔符嗎?
我不知道您是否可以訪問 javascript 后期渲染。 如果你這樣做,你總是可以使用正則表達式來修復你的innerHTML
var text = document.getElementsByClassName("frm_opt_container")[0].innerHTML;
var reg = new RegExp("(<div class=\"combined_field_output\">.*</div>[.\n\r]*)(,)");
while(reg.test(text)){
text = text.replace(reg, "$1")
}
document.getElementsByClassName("frm_opt_container")[0].innerHTML = text
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.