萌面超妹

文章 评论 浏览 29

萌面超妹 2025-02-20 10:28:57

您是对的,您会收到错误,因为什么都没有添加到列表中。
这是因为在您的for循环中,您会迭代变量i,但您声明temp = p。将此行更改为temp = i

另外,您必须将temp = p/10更改为temp = temp/10,就可以了。

此外,您应该重写您的功能,以便即使列表中没有元素也没有异常。例如,您可以检查列表大小是否大于0,然后尝试访问其元素。

You are right, you get the error because nothing is added to the list.
This is because in your for loop, you iterate over the variable i, yet you declare temp = p. Change this line to temp = i.

Also, you have to change temp=p/10 to temp=temp/10 and you're good to go.

In addition, you should rewrite your function so that it does not throw an exception even if there is no element in the list. For example, you could check if the list size is greater than 0 and only then try to access its elements.

找不到最小结果

萌面超妹 2025-02-20 03:03:51

我发现了。

您只需要使用此功能:

    function woocommerce_product_category( $args = array() ) {
    $woocommerce_category_id = get_queried_object_id();
  $args = array(
      'parent' => $woocommerce_category_id
  );
  $terms = get_terms( 'product_cat', $args );
  if ( $terms ) {
      echo '<ul class="woocommerce-categories">';
      foreach ( $terms as $term ) {
          echo '<a href="' .  esc_url( get_term_link( $term ) ) . '"><li class="woocommerce-product-category-page">';
            woocommerce_subcategory_thumbnail( $term );
          echo '<h2>';
          echo '<a href="' .  esc_url( get_term_link( $term ) ) . '" class="' . $term->slug . '">';
          echo $term->name;
          echo '</a>';
          echo '</h2>';
          echo '</li></a>';
      }
      echo '</ul>';
  }
}
add_action( 'woocommerce_before_shop_loop', 'woocommerce_product_category', 100 );

我希望它能帮助某人。谢谢

I figured it out.

You just need to use this function:

    function woocommerce_product_category( $args = array() ) {
    $woocommerce_category_id = get_queried_object_id();
  $args = array(
      'parent' => $woocommerce_category_id
  );
  $terms = get_terms( 'product_cat', $args );
  if ( $terms ) {
      echo '<ul class="woocommerce-categories">';
      foreach ( $terms as $term ) {
          echo '<a href="' .  esc_url( get_term_link( $term ) ) . '"><li class="woocommerce-product-category-page">';
            woocommerce_subcategory_thumbnail( $term );
          echo '<h2>';
          echo '<a href="' .  esc_url( get_term_link( $term ) ) . '" class="' . $term->slug . '">';
          echo $term->name;
          echo '</a>';
          echo '</h2>';
          echo '</li></a>';
      }
      echo '</ul>';
  }
}
add_action( 'woocommerce_before_shop_loop', 'woocommerce_product_category', 100 );

I hope it helped someone. Thanks

如何在类别页面上列出子类别列表。 WooCommerce

萌面超妹 2025-02-19 20:16:43

您可以尝试一下。请根据您的要求编辑弹性值

Row(
 mainAxisAlignment: MainAxisAlignment.spaceBetween,
  children: [
   Flexible(
    flex: 2
    child :Text(
     year,
     style: Theme.of(context).textTheme.subtitle2,
     overflow: TextOverflow.ellipsis,
     ),
   )
   Flexible(
    flex : 8
     child: Row(
       mainAxisAlignment : MainAxisAlignment.end
       mainAxisSize : MainAxisSize.min
       children : [
        icon,
        SizedBox(width: 0.1),
        Flexible(
           child: Text(
             figure,
             style: Theme.of(context).textTheme.subtitle2,
             overflow: TextOverflow.ellipsis,
           ),
        )
       ]
     )
    )
  ]
)

You can try this. Please edit the flex value as per your requirement

Row(
 mainAxisAlignment: MainAxisAlignment.spaceBetween,
  children: [
   Flexible(
    flex: 2
    child :Text(
     year,
     style: Theme.of(context).textTheme.subtitle2,
     overflow: TextOverflow.ellipsis,
     ),
   )
   Flexible(
    flex : 8
     child: Row(
       mainAxisAlignment : MainAxisAlignment.end
       mainAxisSize : MainAxisSize.min
       children : [
        icon,
        SizedBox(width: 0.1),
        Flexible(
           child: Text(
             figure,
             style: Theme.of(context).textTheme.subtitle2,
             overflow: TextOverflow.ellipsis,
           ),
        )
       ]
     )
    )
  ]
)

如何将省略号添加到flutter中的文本中

萌面超妹 2025-02-19 13:48:59

您可以使用combn()创建成对索引,并使用slice()来扩展数据框架。然后仅通过这些行对进行分组并总结。我假设您需要成对组合,但是如果需要,它可以适用于较大的组合。一些处理组的代码&LT;包括2,但如果这些数据不存在,则可以删除。

library(dplyr)
library(purrr)

df1 %>%
  group_by(id) %>%
  slice(c(combn(seq(n()), min(n(), 2)))) %>%
  mutate(id2 = (row_number()-1) %/% 2) %>%
  group_by(id, id2) %>%
  summarise(name = toString(name),
            across(where(is.numeric), sum), .groups = "drop") %>%
  select(-id2) %>%
  bind_rows(df1 %>%
              group_by(id) %>%
              filter(n() > 1), .) %>%
  arrange(id) %>%
  ungroup()

# A tibble: 6 × 4
  id    name           number value
  <chr> <chr>           <int> <int>
1 a     bob                 1     1
2 a     jane                2     2
3 a     bob, jane           3     3
4 b     mark                1     1
5 b     brittney            2     2
6 b     mark, brittney      3     3

编辑:

为了适应所有可能的组合,您可以迭代到最大组大小的值。使用编辑的数据,该数据在第一个组中添加了几行:

map_df(seq(max(table(df2$id))), ~
         df2 %>%
         group_by(id) %>%
         slice(c(combn(seq(n()), .x * (.x <= n())))) %>%
         mutate(id2 = (row_number() - 1) %/% .x) %>%
         group_by(id, id2) %>%
         summarise(name = toString(name),
                   across(where(is.numeric), sum), .groups = "drop")
       ) %>%
  select(-id2) %>%
  arrange(id)

# A tibble: 18 × 4
   id    name                      number value
   <chr> <chr>                      <int> <int>
 1 a     bob                            1     1
 2 a     jane                           2     2
 3 a     sophie                         1     1
 4 a     jeremy                         2     2
 5 a     bob, jane                      3     3
 6 a     bob, sophie                    2     2
 7 a     bob, jeremy                    3     3
 8 a     jane, sophie                   3     3
 9 a     jane, jeremy                   4     4
10 a     sophie, jeremy                 3     3
11 a     bob, jane, sophie              4     4
12 a     bob, jane, jeremy              5     5
13 a     bob, sophie, jeremy            4     4
14 a     jane, sophie, jeremy           5     5
15 a     bob, jane, sophie, jeremy      6     6
16 b     mark                           3     5
17 b     brittney                       4     6
18 b     mark, brittney                 7    11

df2的数据:

df2 <- structure(list(id = c("a", "a", "a", "a", "b", "b"), name = c("bob", 
                                                                     "jane", "sophie", "jeremy", "mark", "brittney"), number = c(1L, 
                                                                                                                                 2L, 1L, 2L, 3L, 4L), value = c(1L, 2L, 1L, 2L, 5L, 6L)), class = "data.frame", row.names = c(NA, 
                                                                                                                                                                                                                              -6L))

You can create pairwise indices using combn() and expand the data frame with these using slice(). Then just group by these row pairs and summarise. I'm assuming you want pairwise combinations but this can be adapted for larger sets if needed. Some code to handle groups < 2 is included but can be removed if these don't exist in your data.

library(dplyr)
library(purrr)

df1 %>%
  group_by(id) %>%
  slice(c(combn(seq(n()), min(n(), 2)))) %>%
  mutate(id2 = (row_number()-1) %/% 2) %>%
  group_by(id, id2) %>%
  summarise(name = toString(name),
            across(where(is.numeric), sum), .groups = "drop") %>%
  select(-id2) %>%
  bind_rows(df1 %>%
              group_by(id) %>%
              filter(n() > 1), .) %>%
  arrange(id) %>%
  ungroup()

# A tibble: 6 × 4
  id    name           number value
  <chr> <chr>           <int> <int>
1 a     bob                 1     1
2 a     jane                2     2
3 a     bob, jane           3     3
4 b     mark                1     1
5 b     brittney            2     2
6 b     mark, brittney      3     3

Edit:

To adapt for all possible combinations you can iterate over the values up to the max group size. Using edited data which has a couple of rows added to the first group:

map_df(seq(max(table(df2$id))), ~
         df2 %>%
         group_by(id) %>%
         slice(c(combn(seq(n()), .x * (.x <= n())))) %>%
         mutate(id2 = (row_number() - 1) %/% .x) %>%
         group_by(id, id2) %>%
         summarise(name = toString(name),
                   across(where(is.numeric), sum), .groups = "drop")
       ) %>%
  select(-id2) %>%
  arrange(id)

# A tibble: 18 × 4
   id    name                      number value
   <chr> <chr>                      <int> <int>
 1 a     bob                            1     1
 2 a     jane                           2     2
 3 a     sophie                         1     1
 4 a     jeremy                         2     2
 5 a     bob, jane                      3     3
 6 a     bob, sophie                    2     2
 7 a     bob, jeremy                    3     3
 8 a     jane, sophie                   3     3
 9 a     jane, jeremy                   4     4
10 a     sophie, jeremy                 3     3
11 a     bob, jane, sophie              4     4
12 a     bob, jane, jeremy              5     5
13 a     bob, sophie, jeremy            4     4
14 a     jane, sophie, jeremy           5     5
15 a     bob, jane, sophie, jeremy      6     6
16 b     mark                           3     5
17 b     brittney                       4     6
18 b     mark, brittney                 7    11

Data for df2:

df2 <- structure(list(id = c("a", "a", "a", "a", "b", "b"), name = c("bob", 
                                                                     "jane", "sophie", "jeremy", "mark", "brittney"), number = c(1L, 
                                                                                                                                 2L, 1L, 2L, 3L, 4L), value = c(1L, 2L, 1L, 2L, 5L, 6L)), class = "data.frame", row.names = c(NA, 
                                                                                                                                                                                                                              -6L))

按组创建组合和总和

萌面超妹 2025-02-19 05:23:04

我找到了Tsengs回答的解决方案,但希望在这里描述它。
解决方案是在另一个问题的答案中找到的,但是这个问题完全不同(我也扩展了答案),因此我不认为这个问题应该被标记为重复。

答案是

” 的每个IIS网站上的值

aspnetcore_environment 这样做是:

  1. 转到IIS中的应用程序,然后选择配置编辑
  2. 选择配置编辑器
  3. 选择system.webserver/aspnetcore(rc2 and rtm)或system.webserver/httpplatform(rc1(rc1)) /code> combobox
  4. 选择applicationhost.config ...在 combobox中中。
  5. 单击EnviroMentVariables元素,然后打开编辑窗口。
  6. 设置您的环境变量。
  7. 关闭窗口,然后单击“应用”。
  8. 另外

,您可以修改applicationhost.config file(通常位于c:\ windows \ system32 \ inetsrv \ inetsrv \ config \ applicationhost.config

,并在下面添加以下条目root &lt; configuration&gt;标签,其中“ my-iis site”是IIS网站的名称。

<location path="my-iis-site">
    <system.webServer>
        <aspNetCore>
            <environmentVariables>
                <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="DEV" />
            </environmentVariables>
        </aspNetCore>
    </system.webServer>
</location>

I've found a solution from Tsengs answer but wish to describe it here for clarity.
The solution is found in the answer to another question however the question is quite different (and I've also expanded upon the answer) so I do not believe this question should be marked as a duplicate.

The answer is here

The solution is to setup different environment variable values on each IIS site for the key ASPNETCORE_ENVIRONMENT

The steps to do so are:

  1. Go to your application in IIS and choose Configuration Editor.
  2. Select Configuration Editor
  3. Choose system.webServer/aspNetCore (RC2 and RTM) or system.webServer/httpPlatform (RC1) in Section combobox
  4. Choose Applicationhost.config ... in From combobox.
  5. Click on enviromentVariables element and open edit window.
  6. Set your environment variables.
  7. Close the window and click Apply.
  8. Done

Alternatively, you can modify your applicationHost.config file (normally located at C:\Windows\System32\inetsrv\config\applicationHost.config

And add the following entry under the root <Configuration> tag, where "my-iis-site" is the name of your IIS site.

<location path="my-iis-site">
    <system.webServer>
        <aspNetCore>
            <environmentVariables>
                <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="DEV" />
            </environmentVariables>
        </aspNetCore>
    </system.webServer>
</location>

如何在.NET Core MVC项目中转换AppSettings.json?

萌面超妹 2025-02-18 22:47:20

Azure SQL数据库支持完整的备份,差速器备份和事务日志备份

差异备份: - 它基于最新的完整数据备份。它仅收集在上次完整数据备份之后更改的数据。您可以定期备份数据库,而无需体验完整数据库备份的负担

Azure SQL数据库提供自动备份

完整的数据备份 - 每周;
差速器备份 - 每12-24小时一次;
交易日志备份 - 每5至10分钟一次。

参考: -
https://learn.microsoft.com/en-us/azure/azure-sql/database/automated-backups-overview?view=Azuresql&amp; tabs = single-database

Azure SQL Database supports Full backup, Differential backup and Transaction log backup.

Differential backup: - It is based on the latest full data backup. it only collects the data which are changed after the last full data backup. You may routinely backup your database without experiencing the burden of complete database backups.

Azure SQL Database provides automated backups.

Full Data Backup - every week;
Differential backup - every 12-24 hours;
Transaction log backup- every 5 to 10 minutes.

Reference: -
https://learn.microsoft.com/en-us/azure/azure-sql/database/automated-backups-overview?view=azuresql&tabs=single-database

如何使用sqlpackage对Azure SQL DB进行增量备份

萌面超妹 2025-02-18 13:48:54

尝试指定要获得字符串的模块。
例如com.example.module.r.string.home_activity_title而不是r.string.home_activity_title

Try specifying the module for which you want the string to be obtained.
E.g. com.example.module.R.string.home_activity_title instead of R.string.home_activity_title

多模块测试中的Android R.String ID混合

萌面超妹 2025-02-18 09:53:20

Next.config.js中禁用严格模式:

const nextConfig = {
  reactStrictMode: false, // React Strict Mode is off
}

module.exports = nextConfig

Disable Strict mode in next.config.js :

const nextConfig = {
  reactStrictMode: false, // React Strict Mode is off
}

module.exports = nextConfig

我在nextJ中选择材料UI有问题

萌面超妹 2025-02-18 08:50:07

这是我们在JavaScript的“奥秘”挣扎时面临的一个非常普遍的问题。让我尝试今天揭开这个谜。

让我们从一个简单的JavaScript函数开始:

function foo(){
    // Do something
    return 'wohoo';
}

let bar = foo(); // 'bar' is 'wohoo' here

这是一个简单的同步函数调用(在下一个代码的每行都“完成其作业”的“完成”),结果与预期的结果相同。

现在,让我们通过在函数中引入一点延迟来添加一些扭曲,以使所有代码都不是“完成”的。因此,它将模仿该功能的异步行为:

function foo(){
    setTimeout( ()=> {
        return 'wohoo';
   }, 1000)
}

let bar = foo() // 'bar' is undefined here

因此您就去了;延迟刚刚打破了我们期望的功能!但是到底发生了什么?好吧,如果您查看代码,这实际上是合乎逻辑的。

函数foo(),在执行后,返回什么都没有(因此返回的值是undefined),但它确实启动了一个计时器,该计时器在1秒钟后执行函数以返回'哇。但是,如您所见,分配给bar的值是Foo()的立即返回的内容,即,即undefined

那么,我们如何解决这个问题


承诺实际上是关于它的含义:这意味着功能可以确保您提供将来的任何输出。因此,让我们在上面的小问题上查看它的行动:

function foo(){
   return new Promise((resolve, reject) => { // I want foo() to PROMISE me something
    setTimeout ( function(){
      // Promise is RESOLVED, when the execution reaches this line of code
       resolve('wohoo') // After 1 second, RESOLVE the promise with value 'wohoo'
    }, 1000 )
  })
}

let bar;
foo().then( res => {
    bar = res;
    console.log(bar) // Will print 'wohoo'
});

因此,摘要是 - 处理类似基于AJAX的呼叫等异步函数,您可以使用承诺来resolve> resolve该值(哪个值(您打算返回)。因此,简而言之,您解决值,而不是返回,在异步函数中。

除了使用然后/catch与Promises合作之外,更新(ASYNC/等待的承诺)

除了使用之外,还有另一种方法。这个想法是识别异步函数,然后等待承诺在移至下一行代码之前解决。它仍然只是引擎盖下的承诺,但采用不同的句法方法。为了使事情变得更清晰,您可以在下面找到一个比较:

然后/捕获版本:

function saveUsers(){
     getUsers()
      .then(users => {
         saveSomewhere(users);
      })
      .catch(err => {
          console.error(err);
       })
 }

async/等待版本:

  async function saveUsers(){
     try{
        let users = await getUsers()
        saveSomewhere(users);
     }
     catch(err){
        console.error(err);
     }
  }

It's a very common issue we face while struggling with the 'mysteries' of JavaScript. Let me try demystifying this mystery today.

Let's start with a simple JavaScript function:

function foo(){
    // Do something
    return 'wohoo';
}

let bar = foo(); // 'bar' is 'wohoo' here

That's a simple synchronous function call (where each line of code is 'finished with its job' before the next one in sequence), and the result is same as expected.

Now let's add a bit of twist, by introducing a little delay in our function, so that all lines of code are not 'finished' in sequence. Thus, it will emulate the asynchronous behavior of the function:

function foo(){
    setTimeout( ()=> {
        return 'wohoo';
   }, 1000)
}

let bar = foo() // 'bar' is undefined here

So there you go; that delay just broke the functionality we expected! But what exactly happened? Well, it's actually pretty logical if you look at the code.

The function foo(), upon execution, returns nothing (thus returned value is undefined), but it does start a timer, which executes a function after 1 second to return 'wohoo'. But as you can see, the value that's assigned to bar is the immediately returned stuff from foo(), which is nothing, i.e., just undefined.

So, how do we tackle this issue?

Let's ask our function for a promise.
Promise is really about what it means: it means that the function guarantees you to provide with any output it gets in future. So let's see it in action for our little problem above:

function foo(){
   return new Promise((resolve, reject) => { // I want foo() to PROMISE me something
    setTimeout ( function(){
      // Promise is RESOLVED, when the execution reaches this line of code
       resolve('wohoo') // After 1 second, RESOLVE the promise with value 'wohoo'
    }, 1000 )
  })
}

let bar;
foo().then( res => {
    bar = res;
    console.log(bar) // Will print 'wohoo'
});

Thus, the summary is - to tackle the asynchronous functions like Ajax-based calls, etc., you can use a promise to resolve the value (which you intend to return). Thus, in short you resolve value instead of returning, in asynchronous functions.

UPDATE (Promises with async/await)

Apart from using then/catch to work with promises, there exists one more approach. The idea is to recognize an asynchronous function and then wait for the promises to resolve, before moving to the next line of code. It's still just the promises under the hood, but with a different syntactical approach. To make things clearer, you can find a comparison below:

then/catch version:

function saveUsers(){
     getUsers()
      .then(users => {
         saveSomewhere(users);
      })
      .catch(err => {
          console.error(err);
       })
 }

async/await version:

  async function saveUsers(){
     try{
        let users = await getUsers()
        saveSomewhere(users);
     }
     catch(err){
        console.error(err);
     }
  }

如何从异步电话中返回响应?

萌面超妹 2025-02-18 08:38:29

您可以使用filesystemwatcher:

$watcher = New-Object -TypeName System.IO.FileSystemWatcher -Property @{Path='c:\temp\lib'; Filter='*_output.txt'; NotifyFilter=[IO.NotifyFilters]::FileName, [IO.NotifyFilters]::LastWrite};
Register-ObjectEvent -InputObject $watcher -EventName Created  -Action {Copy-Item $event.SourceEventArgs.FullPath $($event.SourceEventArgs.FullPath.Replace("output","input"))};
$watcher.EnableRaisingEvents = $true

You could use FileSystemWatcher:

$watcher = New-Object -TypeName System.IO.FileSystemWatcher -Property @{Path='c:\temp\lib'; Filter='*_output.txt'; NotifyFilter=[IO.NotifyFilters]::FileName, [IO.NotifyFilters]::LastWrite};
Register-ObjectEvent -InputObject $watcher -EventName Created  -Action {Copy-Item $event.SourceEventArgs.FullPath $($event.SourceEventArgs.FullPath.Replace("output","input"))};
$watcher.EnableRaisingEvents = $true

镜像文件夹,带有轻微的修改

萌面超妹 2025-02-18 05:18:59

这已经被问到很多次了,一般的想法是必然会在多用户环境中失败 - 一个博客系统听起来像是这种情况。

因此,最好的答案是:不要。考虑一种不同的方法。

将列 category_id 完全从您的表中 - 它不存储其他两个列(id,category)不会存储的任何信息。

您的ID序列列,并且已经以可靠的方式自动提示。

函数category_id没有差距的类别,使用row_number()

This has been asked many times and the general idea is bound to fail in a multi-user environment - and a blog system sounds like exactly such a case.

So the best answer is: Don't. Consider a different approach.

Drop the column category_id completely from your table - it does not store any information the other two columns (id, category) wouldn't store already.

Your id is a serial column and already auto-increments in a reliable fashion.

If you need some kind of category_id without gaps per category, generate it on the fly with row_number():

每组值的自定义序列 /自动插入

萌面超妹 2025-02-18 03:49:32
// variables object
const el = {
    form: document.querySelector(".form"),
    input: document.querySelector(".user-input"),
    list: document.querySelector(".list"),
    date: document.querySelector(".date"),
    time: document.querySelector(".time"),
  };
  //local storage key
  
  const STORAGE_KEY = "tasks-storage-key";
  
  //Create ID
  
  const createId = () =>
    `${Math.floor(Math.random() * 10000)}${new Date().getTime()}`;
  
  //variable of empty array that gets new task
  let taskList = JSON.parse(localStorage.getItem(STORAGE_KEY) ?? "[]");
  
  
  function makeNewTask() {
  
    const data = {
      id: createId(),
      taskNew: el.input.value,
      taskDate: el.date.value,
      taskTime: el.time.value,
    };
  
    return data
  }
  
  
  //function that creates new tasks with date and time
  function display() {
    const tasks = document.createElement("div");
  
    data = makeNewTask();
  
    tasks.innerHTML = `
         <div class="task-content">
          <div class="task" data-id="${data.id}">
          <div class="new-task-created">${data.taskNew}</div>
          <label class="due-date">${data.taskDate}</label>
          <label class="due-time">${data.taskTime}</label>
      </div>
  
      <div class="action-buttons">
          <button onclick="editItem(event)" class="edit" data-id="${data.id}">Edit</button>
          <button onclick="deleteItem(event)" class="delete" data-id="${data.id}">Delete</button>
          <button onclick="completeItem(event)" class="complete" data-id="${data.id}">Complete</button>
      </div>
  </div>`;
  
    taskList.push(tasks);
    el.list.appendChild(tasks);
  }
  
  //event listner that listens for add button.
  function addTask() {
    display();
  }
  
  //function that stores task list.
  function storeList() {
    localStorage.setItem(STORAGE_KEY, JSON.stringify(taskList));
  }
  
  //function that removes task from array with delete button.
  
  function deleteItem() {
    let removeitem = document.querySelector(".task-content");
    removeitem.parentNode.removeChild(removeitem);
    localStorage.removeItem(STORAGE_KEY);
  }
  
  //function that removes stored task when deleted.
  
  //function that that edits tasks with date and time.
  function editItem(){
  
  }
  
  //function that that completes task.
  function completeItem(event) {
    const element = event.target.closest('.task-content')
    console.log(element)
    let taskItem = element.querySelector(".new-task-created");
    let dateItem = element.querySelector(".due-date");
    let timeItem = element.querySelector(".due-time");
    // style..
    taskItem.style.textDecoration = "line-through";
    dateItem.style.textDecoration = "line-through";
    timeItem.style.textDecoration = "line-through";
  }
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="../css/main.css">
    <script src="js/main.js" defer></script>
    <title>To Do Application</title>
</head>

<body>
    <div class="form">
        <input class ="user-input" type="text">
        <input class="date" type="date">
        <input class="time" type="time">
        <button onclick="addTask()" class="add" id="add">+</button>
    </div>

    <div class="list"></div>
    <!--
     <div class="task-content">
        <div class="task" data-id="${id}">
        <div class="new-task-created">${taskNew}</div>
        <label class="due-date">${taskDate}</label>
        <label class="due-time">${taskTime}</label>
    </div>

    <div class="atcion-buttons">
        <button onclick="editItem()" class="edit" data-id="${id}">Edit</button>
        <button onclick="deleteItem()" class="delete" data-id="${id}">Delete</button>
        <button onclick="completeItem()" class="complete" data-id="${id}">Complete</button>
    </div>
</div>
-->
</body>

</html>

// variables object
const el = {
    form: document.querySelector(".form"),
    input: document.querySelector(".user-input"),
    list: document.querySelector(".list"),
    date: document.querySelector(".date"),
    time: document.querySelector(".time"),
  };
  //local storage key
  
  const STORAGE_KEY = "tasks-storage-key";
  
  //Create ID
  
  const createId = () =>
    `${Math.floor(Math.random() * 10000)}${new Date().getTime()}`;
  
  //variable of empty array that gets new task
  let taskList = JSON.parse(localStorage.getItem(STORAGE_KEY) ?? "[]");
  
  
  function makeNewTask() {
  
    const data = {
      id: createId(),
      taskNew: el.input.value,
      taskDate: el.date.value,
      taskTime: el.time.value,
    };
  
    return data
  }
  
  
  //function that creates new tasks with date and time
  function display() {
    const tasks = document.createElement("div");
  
    data = makeNewTask();
  
    tasks.innerHTML = `
         <div class="task-content">
          <div class="task" data-id="${data.id}">
          <div class="new-task-created">${data.taskNew}</div>
          <label class="due-date">${data.taskDate}</label>
          <label class="due-time">${data.taskTime}</label>
      </div>
  
      <div class="action-buttons">
          <button onclick="editItem(event)" class="edit" data-id="${data.id}">Edit</button>
          <button onclick="deleteItem(event)" class="delete" data-id="${data.id}">Delete</button>
          <button onclick="completeItem(event)" class="complete" data-id="${data.id}">Complete</button>
      </div>
  </div>`;
  
    taskList.push(tasks);
    el.list.appendChild(tasks);
  }
  
  //event listner that listens for add button.
  function addTask() {
    display();
  }
  
  //function that stores task list.
  function storeList() {
    localStorage.setItem(STORAGE_KEY, JSON.stringify(taskList));
  }
  
  //function that removes task from array with delete button.
  
  function deleteItem() {
    let removeitem = document.querySelector(".task-content");
    removeitem.parentNode.removeChild(removeitem);
    localStorage.removeItem(STORAGE_KEY);
  }
  
  //function that removes stored task when deleted.
  
  //function that that edits tasks with date and time.
  function editItem(){
  
  }
  
  //function that that completes task.
  function completeItem(event) {
    const element = event.target.closest('.task-content')
    console.log(element)
    let taskItem = element.querySelector(".new-task-created");
    let dateItem = element.querySelector(".due-date");
    let timeItem = element.querySelector(".due-time");
    // style..
    taskItem.style.textDecoration = "line-through";
    dateItem.style.textDecoration = "line-through";
    timeItem.style.textDecoration = "line-through";
  }
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="../css/main.css">
    <script src="js/main.js" defer></script>
    <title>To Do Application</title>
</head>

<body>
    <div class="form">
        <input class ="user-input" type="text">
        <input class="date" type="date">
        <input class="time" type="time">
        <button onclick="addTask()" class="add" id="add">+</button>
    </div>

    <div class="list"></div>
    <!--
     <div class="task-content">
        <div class="task" data-id="${id}">
        <div class="new-task-created">${taskNew}</div>
        <label class="due-date">${taskDate}</label>
        <label class="due-time">${taskTime}</label>
    </div>

    <div class="atcion-buttons">
        <button onclick="editItem()" class="edit" data-id="${id}">Edit</button>
        <button onclick="deleteItem()" class="delete" data-id="${id}">Delete</button>
        <button onclick="completeItem()" class="complete" data-id="${id}">Complete</button>
    </div>
</div>
-->
</body>

</html>

我希望我的 - 在按下完整按钮时,请应用程序在每个任务上遍历一条线

萌面超妹 2025-02-18 00:39:37

patchQueryData将“浸入式补丁”应用于缓存条目,而updateQueryData允许您针对缓存条目运行一个函数,并且只需“更改”它。在内部,将创建一个补丁,然后调用UpdateQueryData。因此,从本质上讲,PatchQueryData是一个实现细节。它对大多数人来说不会有用,但是有些人可能会看到其中的好处,因此它也暴露了。

patchQueryData applies an "immer patch" to the cache entry, while updateQueryData allows you to run a function against your cache entry and just "change" it. Internally, that will create a patch and then call updateQueryData. So, essentially patchQueryData is an implementation detail. It will not be useful for most people, but some people might see benefit in it, so it is exposed as well.

Redux Toolkit查询中的UpdateQueryData()和PatchQueryData()有什么区别?

萌面超妹 2025-02-17 12:02:07

我认为,因为文本包含太空更新很奇怪。无论如何,如果您使用宽度:Max-Content;在横幅类中,它不会振动怪异,并且宽度仍然仅包含在文本中。这仅起作用,因为该元素仅包含文本,如果您将其他div放入其中,则可能需要width:fit-content;

I think because the text contains spaces it updates weird. Anyway if you use width: max-content; in the banner class it won't vibrate weird and the width is still contained to only the text. This only works because the element only contains text if you put other divs inside you might need width: fit-content;

为什么添加宽度时伪元素会振动?

萌面超妹 2025-02-17 06:01:46

您的构造函数实现类型必须是所有声明的超级文档,如以下内容:

export interface ParamInterface {
  a: number;
  b: number;
  c: number;
  d?: number;
  e?: number;
  f?: number;
}
export class MyClass {
  a: number;
  b: number;
  c: number;
  d?: number;
  e?: number;
  f?: number;

  constructor({ a, b, c, d, e, f }: ParamInterface);
  constructor(a: number, b: number, c: number, d?: number, e?: number, f?: number);
  constructor(...values: [ParamInterface] | [a: number, b: number, c: number, d?: number, e?: number, f?: number]) {
    if (values.length == 1) {
      const { a, b, c, d, e, f } = values[0];
      // assign values
    } else {
      const [a, b, c, d, e, f] = values;
      // assign values
    }
  }
}

在这里我们有两个构造函数声明:

constructor({ a, b, c, d, e, f }: ParamInterface);
constructor(a: number, b: number, c: number, d?: number, e?: number, f?: number);

一个实现:

constructor(...values: [ParamInterface] | [a: number, b: number, c: number, d?: number, e?: number, f?: number]) {
  // ...
}

类型声明可以简化:

export interface ParamInterface {
  a: number;
  b: number;
  c: number;
  d?: number;
  e?: number;
  f?: number;
}
type TupleParameters = [a: number, b: number, c: number, d?: number, e?: number, f?: number];

export class MyClass {
  // all fields

  constructor({ a, b, c, d, e, f }: ParamInterface);
  constructor(...values: TupleParameters);
  constructor(...values: [ParamInterface] | TupleParameters) {
    // unchanged
  }
}

Your constructor implementation type must be supertype of all declarations, like following:

export interface ParamInterface {
  a: number;
  b: number;
  c: number;
  d?: number;
  e?: number;
  f?: number;
}
export class MyClass {
  a: number;
  b: number;
  c: number;
  d?: number;
  e?: number;
  f?: number;

  constructor({ a, b, c, d, e, f }: ParamInterface);
  constructor(a: number, b: number, c: number, d?: number, e?: number, f?: number);
  constructor(...values: [ParamInterface] | [a: number, b: number, c: number, d?: number, e?: number, f?: number]) {
    if (values.length == 1) {
      const { a, b, c, d, e, f } = values[0];
      // assign values
    } else {
      const [a, b, c, d, e, f] = values;
      // assign values
    }
  }
}

Here we have two constructor declarations:

constructor({ a, b, c, d, e, f }: ParamInterface);
constructor(a: number, b: number, c: number, d?: number, e?: number, f?: number);

and one implementation:

constructor(...values: [ParamInterface] | [a: number, b: number, c: number, d?: number, e?: number, f?: number]) {
  // ...
}

Type declaration can be a little simplified:

export interface ParamInterface {
  a: number;
  b: number;
  c: number;
  d?: number;
  e?: number;
  f?: number;
}
type TupleParameters = [a: number, b: number, c: number, d?: number, e?: number, f?: number];

export class MyClass {
  // all fields

  constructor({ a, b, c, d, e, f }: ParamInterface);
  constructor(...values: TupleParameters);
  constructor(...values: [ParamInterface] | TupleParameters) {
    // unchanged
  }
}

构造函数超负荷带有打字稿中有或没有破坏接口的构造函数,以允许位置或命名ARGS

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文