我有一个主题列表
const topics = getPromptCategories();
Run Code Online (Sandbox Code Playgroud)
看起来像
[ { category: "cat1", attempts: 0 }, {category: "cat2", attempts: 0 } ]
Run Code Online (Sandbox Code Playgroud)
所以我的界面是
interface topicInterface {
category: string;
attempts: number;
}
Run Code Online (Sandbox Code Playgroud)
我试图从主题中派生出一些按钮,所以我这样做
const topicButtons = topics.map((topic) => {
return <button>{topic.category}</button>;
});
Run Code Online (Sandbox Code Playgroud)
但它Object is of type 'unknown'在 {topic.category} 上对我尖叫
如果我将界面添加到主题,topic: topicInterface它现在会告诉我一些不同的东西
Argument of type '(topic: topicInterface) => JSX.Element' is not assignable to parameter of type '(value: unknown, index: number, array: unknown[]) => Element'.
Run Code Online (Sandbox Code Playgroud)
我是打字稿新手。我错过或忽略了什么?
我有一组主题。我试图循环遍历它们,并根据我指定的秒数一次向它们添加“glow”类。当一个元素发光时,前一个元素不应再发光。
<div class="center" id="topics">
<div class="row">
<div class="topic" id="fade1">Introduction and Overview</div>
<div class="topic" id="fade4">Topic 6</div>
<div class="topic" id="fade7">Accounting Topic</div>
</div>
<div class="row">
<div class="topic" id="fade2">Topic Navigation</div>
<div class="topic" id="fade5">Topic Changes</div>
<div class="topic" id="fade8">Topic 8</div>
</div>
<div class="row">
<div class="topic" id="fade3">More Topics</div>
<div class="topic" id="fade6">Elements</div>
<div class="topic" id="fade9">Conclusion</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这就是我定义它们发光的秒数间隔的方式。因此,当其中一个发光时,其余的应该不再发光。
$.glowElements([
{target: "#fade1", seconds: 4},
{target: "#fade2", seconds: 9},
{target: "#fade3", seconds: 20},
{target: "#fade4", seconds: 22},
{target: "#fade5", seconds: 23},
{target: "#fade5", seconds: 24}
]);
Run Code Online (Sandbox Code Playgroud)
我处理发光的代码:
$.glowElements = function(list){ …Run Code Online (Sandbox Code Playgroud) 我的表看起来像这样:
artist_id | song_id | user_id
a1 s1 u1
a1 s2 u1
a2 s9 u1
a3 s15 u2
Run Code Online (Sandbox Code Playgroud)
我希望我的输出看起来像:
Array
(
[u1] => Array
(
[a1] => Array
(
[0] => s1
[1] => s2
)
[a2] => Array
(
[0] => s9
)
)
[u2] => Array
(
[a3] => Array
(
[0] => s15
)
)
Run Code Online (Sandbox Code Playgroud)
)
我应该从哪里开始?
我不确定我的方法是否最有效:
抓住并分组user_id,循环通过它们.
user_id抓住每个人artist_id.
对于每个artist_id抓住song_id下面的s.
有没有办法进行这一个查询?
我有一系列项目。我想确保每个项目都符合特定标准。
我写了这个 for 循环,但我不确定它是否最有效。有一个更好的方法吗?
let match = 0;
for (var i = 0; i < lastPressed.length; i++) {
if (lastPressed[i].o.length === 1 && lastPressed[i].n.length === 0) {
match++;
} else {
break;
}
}
if(match === lastPressed.length) return true;
return false;
Run Code Online (Sandbox Code Playgroud)