我需要在字符串中查找/替换或转换 pilcrow/偏微分字符,因为它们当前显示为 ?。
我认为会起作用但不起作用的东西:
const value = 'Javascript Regex pattern for Pilcrow (¶) or Partial Differential (?) character';
const matches = value.match(/\u2029/gmi);
console.log(matches);
Run Code Online (Sandbox Code Playgroud)
但返回空。
老实说,我什至不确定如何实现我需要做的事情。
我有两个表:tbl_product
,tbl_product_category
我想制作一个带有关键字并返回与关键字匹配的所有产品和产品类别的API。如果结果来自,tbl_product
则它也返回它是乘积。如果结果来自,tbl_product_category
则它也返回它是类别。
tbl_product_catagory.findAll({
raw: true,
attributes: [[sequelize.literal("catagory_name"), "type"]],
include: [{
model: tbl_product,
attributes: [[sequelize.literal(["product_name"]), "name"]],
required: false,
where: {
product_name: {
[Op.like]: "%" + data.word + "%"
}
}
}]
})
Run Code Online (Sandbox Code Playgroud) 我有一个以下形式的 JSON 对象:
{
"Task11c-0-20181209-12:59:30-65611" : {
"attributes" : {
"configname" : "Task11c",
"datetime" : "20181209-12:59:30",
"experiment" : "Task11c",
"inifile" : "lab1.ini",
"iterationvars" : "",
"iterationvarsf" : "",
"measurement" : "",
"network" : "Manhattan1_1C",
"processid" : "65611",
"repetition" : "0",
"replication" : "#0",
"resultdir" : "results",
"runnumber" : "0",
"seedset" : "0"
},
......
},
......
"Task11b-12-20181209-13:03:17-65612" : {
....
....
},
.......
}
Run Code Online (Sandbox Code Playgroud)
我只报告了第一部分,但总的来说,我还有许多其他子对象与Task11c-0-20181209-12:59:30-65611
. 它们都有一个共同的词首字母Task
。我想processid
从每个子对象中提取。我试图在 bash 中使用通配符,但似乎不可能。
我还阅读了match()函数,但它适用于字符串而不是 json 对象。
感谢您的支持。
const inquirer = require("inquirer")
var questions = [
{
type: "number",
name: "name",
message: "Please the number of players",
validate: function (name) {
var valid = Number.isInteger(name)
return valid || `Please enter a valid whole number`
},
},
]
function promptUser() {
inquirer
.prompt(questions)
.then((answers) => {
console.log(`You entered ${answers["name"]}!`)
})
.catch((error) => console.log(`Please enter a number`))
}
promptUser()
Run Code Online (Sandbox Code Playgroud)
考虑到上面的代码,我在类似这样的旧视频中注意到,如果您包含验证并且失败,输入将被清除。然而,就我而言,我得到的 NaN 不会自动清除。假设我启动应用程序并输入“abcdefg”:
? Please the number of players NaN
>> Please enter a valid whole number
Run Code Online (Sandbox Code Playgroud)
如果我输入任何内容,它只会添加到 NaN …
根据此 SO thread,flatMap
或者reduce
当需要映射和过滤一组对象时推荐,特别是如果他们想避免多次循环遍历集合。就我个人而言,我更喜欢使用它flatMap
,因为我认为它更容易阅读,但这当然完全是主观的。除了 的浏览器兼容性问题之外flatMap
,是否普遍推荐一种方法或比另一种方法更有利(可能是因为但不限于性能或可读性的原因)?
更新:这是来自 flatMap 过滤的参考答案的示例:
var options = [{
name: 'One',
assigned: true
},
{
name: 'Two',
assigned: false
},
{
name: 'Three',
assigned: true
},
];
var assignees = options.flatMap((o) => (o.assigned ? [o.name] : []));
console.log(assignees);
document.getElementById("output").innerHTML = JSON.stringify(assignees);
Run Code Online (Sandbox Code Playgroud)
<h1>Only assigned options</h1>
<pre id="output"> </pre>
Run Code Online (Sandbox Code Playgroud)
我正在使用 React Hook Forms。
<Controller
control={control}
rules={{ required: "Required" }}
error={errors.state ? true : false}
helperText={errors.state && errors.state.message}
name="state"
as={
<AutoComplete
options={stateOptions}
onChange={selectStateHandler}
label="State"
value={selectedState}
/>
}
/>
Run Code Online (Sandbox Code Playgroud)
辅助文本正在使用TextField
但不与Autocomplete
. TextField
边框颜色因错误而变化,我想要与Autocomplete
.
我一直在寻找自动完成组件的(https://material-ui.com/api/autocomplete/)API,但我似乎找不到一种方法(从我有限的 javascript 知识)只显示文本字段下方有一定数量的选项。
我正在尝试将搜索功能与超过 7,000 条数据结合起来,但我不想立即显示所有数据。如何将选项限制为最多 10 个建议?
所以有多种方法可以在 JS 中转换和转换Array
为 a Set
。
示例 #2绝对是O(n),因为它遍历数组的所有元素。示例 #1 的情况是否相同?或者JS在后台为我们做一些优化?
如果是,使用Example #1有什么缺点吗?
const arr = [ 1, 3, 2, 3, 5 ];
const set = new Set(arr);
console.log(set);
/*
Output: Set { 1, 3, 2, 5 }
*/
Run Code Online (Sandbox Code Playgroud)
const arr = [ 1, 3, 2, 3, 5 ];
const set = new Set();
arr.map(item => set.add(item));
console.log(set);
/*
Output: Set { 1, 3, 2, 5 }
*/
Run Code Online (Sandbox Code Playgroud) 当我使用自动完成来获取所选日期时,所选选项不会被过滤。因此我能够选择相同数据的多个实例。虽然当我删除 OnChange 道具时它会给出结果,但现在我无法更新状态。
<Autocomplete
multiple
name="ClassSchedule"
onChange={(event, value) => setDays(value)}
ChipProps={{
style: {
backgroundColor: "#2EC5B6",
borderRadius: "5px",
color: "#fff",
fontFamily: "Source Sans Pro",
},
}}
id="tags-standard"
options={[
{ title: "sunday" },
{ title: "monday" },
{ title: "tuesday" },
{ title: "wednesday" },
{ title: "thursday" },
{ title: "friday" },
{ title: "saturday" },
]}
getOptionLabel={(option) => option.title}
renderInput={(params) => (
<CssTextField
{...params}
style={{
borderRadius: "10px",
backgroundColor: "#F5FCFB",
fontFamily: "Source Sans Pro",
}}
variant="outlined"
id="custom-css-outlined-input"
/>
)}
/>
Run Code Online (Sandbox Code Playgroud) 我有开关,它看起来很长:
switch (+f.level) {
case 10:
this.region = f
break
case 20:
this.aregion = f
break
case 30:
this.district = f
break
case 40:
this.city = f
break
case 50:
this.intraCityTerritoryn = f
break
}
Run Code Online (Sandbox Code Playgroud)
我试图修改它:
public directory = {
{10: this.region},
{20: this.aregion},
{30: this.district},
{40: this.city}
};
Run Code Online (Sandbox Code Playgroud)
然后我尝试通过 key 获取 varaible 并分配f
。
我有一个名为表tbl_documents
,它记录文件象的一些细节doc_no
,branch_no
,doc_name
,date
等.
我在我的函数中包含了以下行来获取tbl_documents
表的所有字段.
...
$this->db->select('*')
->from('tbl_documents')
->where('status', 1, '', FALSE);
...
Run Code Online (Sandbox Code Playgroud)
该功能正常工作并生成正确的输出.但branch_no
在tbl_documents
表与相关branch_no
的tbl_branch
表.它还包括另一个领域,branch_names
如:管理员,帐户,IT等.
如果我使用以下代码获取所需输出的分支名称,则会触发错误.
$this->db->select('*')
->from('tbl_documents')
->join('tbl_branch', 'tbl_branch.branch_id=tbl_documents.branch_id', 'left')
->where('status', 1, '', FALSE);
Run Code Online (Sandbox Code Playgroud)
可能有什么不对?谁能帮助我?
假设我的数组是:
const array = [20, 30, 21, 15, 80];
Run Code Online (Sandbox Code Playgroud)
如果我想例如 console.log 它,它将显示以下内容:
20,30,21,15,80
Run Code Online (Sandbox Code Playgroud)
但我希望输出是
20 30 21 15 80
Run Code Online (Sandbox Code Playgroud)
在 console.log 中。
如何使用空格将其分开?我尝试使用 .split 和其他东西,但没有用。提前致谢!!
javascript ×9
material-ui ×3
reactjs ×3
arrays ×2
big-o ×1
codeigniter ×1
controller ×1
forms ×1
inquirer ×1
inquirerjs ×1
jq ×1
json ×1
mysql ×1
node.js ×1
regex ×1
sequelize.js ×1
set ×1
typescript ×1