小编mns*_*nsc的帖子

尝试访问本地存储时,javascript/html5中的Dom Exception 18

我有以下html尝试在本地存储中设置一个密钥.

<!DOCTYPE html>
<html>
<head>
  <title>Test</title>
  <script>
  document.addEventListener('DOMContentLoaded', loaded, false);
  function loaded(){
    try {
      window.localStorage.setItem("Test", "SetItemValue");
      document.getElementById("test").innerHTML = "Test OK";
    } catch (err) {
      document.getElementById("test").innerHTML = "Test FAIL<br>" + err.message;
    }
  }
  </script>
</head>
<body>
  <div id="test">Testing...</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

在单个iPhone5上,这会导致以下异常.

测试FAIL
SecurityError:DOM异常18

使用相同的iOs版本(7.0.2)测试的其他iPhone(另外三个)也适用.

我已经从https://xydomain.tldhttp://x.domain.tld测试了上述页面,但具有相同的异常.

关于"DOM异常18"的其他问题似乎与安全设置有关,例如.测试localhost,但通过https链接远程内容.但这是一个简单的html页面,它只是试图访问本地存储.

javascript iphone html5 ios7

5
推荐指数
1
解决办法
1461
查看次数

使用linq更新对象的性能更佳

我有两个自定义对象列表,如果另一个列表中的对象与另一对字段匹配,则希望为一个列表中的所有对象更新字段.

此代码更好地解释了问题,并产生了我想要的结果.但是对于较大的列表20k和具有匹配对象的20k列表,这需要相当长的时间(31秒).通过使用通用列表Find(Predicate)方法,我可以用~50%来改善这一点.

using System;
using System.Linq;
using System.Linq.Expressions;
using System.Collections.Generic;
namespace ExperimentFW3
{
    public class PropValue
    {
        public string Name;
        public decimal Val;
        public decimal Total;
    }
    public class Adjustment
    {
        public string PropName;
        public decimal AdjVal;
    }
    class Program
    {
        static List<PropValue> propList;
        static List<Adjustment> adjList;

        public static void Main()
        {
            propList = new List<PropValue>{
                new PropValue{Name = "Alfa", Val=2.1M},
                new PropValue{Name = "Beta", Val=1.0M},
                new PropValue{Name = "Gamma", Val=8.0M}
            };
            adjList = new List<Adjustment>{
                new Adjustment{PropName = "Alfa", …
Run Code Online (Sandbox Code Playgroud)

c# linq optimization performance linq-to-objects

2
推荐指数
1
解决办法
1343
查看次数