GVKun编程网logo

在数组中如何存储IndexValue和Name(存放数组的数组)

10

在本文中,您将会了解到关于在数组中如何存储IndexValue和Name的新资讯,同时我们还将为您解释存放数组的数组的相关在本文中,我们将带你探索在数组中如何存储IndexValue和Name的奥秘,

在本文中,您将会了解到关于在数组中如何存储IndexValue和Name的新资讯,同时我们还将为您解释存放数组的数组的相关在本文中,我们将带你探索在数组中如何存储IndexValue和Name的奥秘,分析存放数组的数组的特点,并给出一些关于$watch中的oldvalue和newValue、.net DateTime MaxValue一旦存储在数据库中就不同了、.net – F#int.MaxValue是“不是有效的常量表达式”,但System.Int32.MaxValue是?、Android studio 中NameValuePair跟BasicNameValuePair 不能正常导包问题的实用技巧。

本文目录一览:

在数组中如何存储IndexValue和Name(存放数组的数组)

在数组中如何存储IndexValue和Name(存放数组的数组)

您可以尝试这样的事情。

data: Array<{Index: number; File: File}>

for(var i=0;i<=files.length - 1;i++){
  this.data.push({ Index: i,File: files[i] });
 }

console.log(this.data);
,

如果您特别想跟踪和更新键值条目,则可以使用Map。

// Example adapted from MDN network
const map1 = new Map();
map1.set(0,'Something.jpg');
map1.set(1,'Something1.jpg');

console.log(map1.get(0)); // 'Something.jpg'
console.log(map1.get(1)); // 'Something1.jpg'

$watch中的oldvalue和newValue

$watch中的oldvalue和newValue

vue中提供了$watch的方法来做对象变化的监听,而且在callback中会返回两个对象,分别是oldValue和newValue.
顾名思义,这两个对象就是对象发生变化前后的值。
但是在使用过程中我发现这两个值并不总是预期的。

定义data的值

data: {
    arr: [{
      name: ''笨笨'',
      address: ''上海''
    }, {
      name: ''笨笨熊'',
      address: ''北京''
    }],
    obj: {
      name: ''呆呆'',
      address: ''苏州''
    },
    str: ''哈哈哈''
  }

定义watch

watch: {
    arr: function(newValue, oldValue) {
      console.log(newValue, oldValue)
      console.log(JSON.stringify(oldValue) === JSON.stringify(newValue))
    },
    obj: function(newValue, oldValue) {
      console.log(newValue, oldValue)
      console.log(JSON.stringify(oldValue) === JSON.stringify(newValue))
    },
    str: function(newValue, oldValue) {
      console.log(newValue, oldValue)
      console.log(JSON.stringify(oldValue) === JSON.stringify(newValue))
    },
  }

定义事件触发

methods: {
    test() {
      this.arr.push({
        name: 9
      })
      this.$set(this.obj, ''i'', 0)
      this.str = ''''
    },
    test1() {
      this.arr = [{
        name: ''000''
      }]
      this.obj = {
        name: 999
      }
      this.str = ''123''
    }
  }

测试结果为

对数组进行push操作和对Obj进行$set操作,虽然都可能触发watch事件,但是在callback返回的结果中,oldValue和newValue相同。字符串对象如预期返回

在对数组和Obj统一进行赋值操作时,watch触发并且oldValue和newValue如预期返回

关于watch的其他测试可以参考我之前的文章
vue中正确的使用watch进行监听

测试地址(测试时请打开控制台)
https://zuank.github.io/notes...

.net DateTime MaxValue一旦存储在数据库中就不同了

.net DateTime MaxValue一旦存储在数据库中就不同了

如何解决.net DateTime MaxValue一旦存储在数据库中就不同了?

|| 当我在数据库中存储具有DateTime.MaxValue值的date属性并将其取回时,存储的值不等于DateTime.MaxValue。刻度属性关闭。为什么是这样? 使用MS sql,日期字段的数据类型为\''datetime \''     

解决方法

因为SQL datetime具有较低的分辨率。   MS SQL中的DateTime数据类型   表示来自的日期和时间数据   1753年1月1日至9999年12月31日,   精度为一   三十分之一秒或3.33   毫秒。值四舍五入为   .000,.003或.007的增量   毫秒。 资源   .Net中的DateTime值类型   代表日期和时间   0001年1月1日午夜12:00:00   安诺·多米尼(共同时代)   9999年12月31日下午11:59:59   (C.E.)时间值以   100纳秒单位称为刻度。 资源     ,很有可能是因为.NET DateTime没有直接转换为SQL DateTime类型。 我都将设置该值,然后检查“ 0”的刻度。     ,我必须承认我对此不确定,但这可能与datetime的准确性有关吗? 在此处进行快速搜索是有关 DateTime的精度和准确性 也可能在c#和sql中的datetime精度之间存在不匹配吗?     ,您要在其中存储此值的数据字段是哪种类型? .NET
DateTime
的最大值可能超过了数据库引擎中等效数据类型的容量。     ,MS SQL Server在最低级别的日期上做了一些奇怪的事情。例如,考虑以下脚本:
select
    test1 = dateadd(ms,-1,convert(datetime,\''20110504\'')),test2 = dateadd(ms,-2,test3 = dateadd(ms,-3,test4 = dateadd(ms,-4,test5 = dateadd(ms,-5,test6 = dateadd(ms,-6,\''20110504\''))
返回:
test1                   test2                   test3                   test4                   test5                   test6
----------------------- ----------------------- ----------------------- ----------------------- ----------------------- -----------------------
2011-05-04 00:00:00.000 2011-05-03 23:59:59.997 2011-05-03 23:59:59.997 2011-05-03 23:59:59.997 2011-05-03 23:59:59.993 2011-05-03 23:59:59.993
如您所见,MS SQL仅处理毫秒数到最接近的3。如果在这两者之间进行取整,则四舍五入。当DateTime.MaxValue存储在SQL中时,可能就是这种情况。     

.net – F#int.MaxValue是“不是有效的常量表达式”,但System.Int32.MaxValue是?

.net – F#int.MaxValue是“不是有效的常量表达式”,但System.Int32.MaxValue是?

TL; DR:F#编译器在本上下文中将int解释为 int operator,如 determined by Eugene Fotin和 expanded upon by Gene Belitski.最佳解决方法是使用system.int32.MaxValue或唯一类型别名,如下所述.

考虑以下记录类型:

type User = {
    Username : string
}

我想要用户名至少三个字符长,所以我使用StringLength属性.没有最大长度,所以我设置为int.MaxValue:

type User = {
    [<StringLength(int.MaxValue,MinimumLength=3)>]
    Username : string
}

这给我以下错误:

This is not a valid constant expression or custom attribute value.

一切都是桃子,如果我使用system.int32代替:

type User = {
    [<StringLength(system.int32.MaxValue,MinimumLength=3)>]
    Username : string
}

它也编译如果我alias int:

type User = {
    [<StringLength(num.MaxValue,MinimumLength=3)>]
    Username : string
}
and num = int

或完全限定类型:

type User = {
    [<StringLength(Microsoft.FSharp.Core.int.MaxValue,MinimumLength=3)>]
    Username : string
}

我检查了F#源和int is defined exactly as you would expect:

type int32 = system.int32
// Then,a few lines later…
type int = int32

这是怎么回事?我假设F#原始类型在大多数情况下与其他类型是可互换的,但它看起来像我的心理模型中缺少的东西.

解决方法

这就是F#类型推论在不同上下文中的工作原理,其中不同的句法实体巧合地具有相同的名称,如果int可能是以下任何一种:

> function int:’T> int的全名为Microsoft.FSharp.Core.Operators.int
>键入int = int32的全名Microsoft.FSharp.Core.int
> type int&”Measure> =全名为Microsoft.FSharp.Core.int< _>

演示此工作的一种方法将是以下情况:如果我们刚刚输入

int;;

在FSI中,我们会得到类似的东西

val it : (int -> int) = <fun:it@3>

换句话说,它是一个不能与其相关联的MaxValue属性的函数:

> int.MaxValue;;

int.MaxValue;;
----^^^^^^^^

... error FS0039: The field,constructor or member 'MaxValue' is not defined

同样适用于int32,当在表达式的上下文中使用时,它被FSI推断为仅具有signature(int – > int32)的另一个函数.

现在谈到

type num = int

在这个上下文中,int被推断为system.int32的类型名称缩写,所以num也是一个类型缩写,但是现在名称模糊性没有地方,所以num.MaxValue是我们期望的,我们期望的是在FSI

> num.MaxValue;;
val it : int = 2147483647

最后,当您使用Microsoft.FSharp.Core.int时,您明确地引用了类型实体,没有任何歧义的地方,因此它可以按预期工作.

返回到你的用例属性参数 – 在这个上下文中,int被类型推断作为表达式的一部分来处理,以提供参数值,即作为函数,除非你明确或间接设置另一个解释.

Android studio 中NameValuePair跟BasicNameValuePair 不能正常导包问题

Android studio 中NameValuePair跟BasicNameValuePair 不能正常导包问题

Android studio 中NameValuePair跟BasicNameValuePair 不能正常导包问题

针对一个post请求,android studio中无法正常导入以下两个包:

 

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

Cannot resolve symbol NameValuePair

最后解决方案是:

在module文件中加入了

android {
...
useLibrary ''org.apache.http.legacy''

dependencies {
    ...
    compile ''org.apache.httpcomponents:httpcore:4.4.1''
    compile ''org.apache.httpcomponents:httpclient:4.5''
}

}

到此问题得到解决,如果还是报错出现如下:

compile ''org.apache.httpcomponents:httpclient:4.5.5''

出现红色报错线并提示下列错误:

httpclient defines classes that conflict with classes now provided by Android. Solutions include finding newer versions or alternative libraries that don''t have the same problem (for example, for httpclient use HttpUrlConnection or okhttp instead), or repackaging the library using something like jarjar. less... (Ctrl+F1) 

There are a number of libraries that duplicate not just functionality of the Android platform but using the exact same class names as the ones provided in Android -- for example the apache http classes. This can lead to unexpected crashes.  To solve this, you need to either find a newer version of the library which no longer has this problem, or to repackage the library (and all of its dependencies) using something like the jarjar tool, or finally, rewriting the code to use different APIs (for example, for http code, consider using HttpUrlConnection or a library like okhttp).  Issue id: DuplicatePlatformClasses

解决办法:

在android中添加下列代码:

 configurations {
        all {
            exclude module: ''httpclient''
            exclude module: ''commons-logging''
        }
    }

截图如下:

 

重新点击出错语句编译即可解决。

今天的关于在数组中如何存储IndexValue和Name存放数组的数组的分享已经结束,谢谢您的关注,如果想了解更多关于$watch中的oldvalue和newValue、.net DateTime MaxValue一旦存储在数据库中就不同了、.net – F#int.MaxValue是“不是有效的常量表达式”,但System.Int32.MaxValue是?、Android studio 中NameValuePair跟BasicNameValuePair 不能正常导包问题的相关知识,请在本站进行查询。

本文标签: