小编Cap*_*ohn的帖子

从父对象创建子对象实例的最佳方法

我正在从父对象创建一个子对象.所以场景是我有一个对象和一个子对象,它为我想要搜索的场景添加了一个距离属性.我选择使用继承,因为我的UI与搜索对象或对象列表等效地工作,而不是位置搜索的结果.所以在这种情况下,继承似乎是一个明智的选择.

目前我需要MyObjectSearch从一个实例生成一个新对象MyObject.目前我通过逐个设置属性手动在构造函数中执行此操作.我可以使用反射,但这会很慢.有没有更好的方法来实现这种对象增强?

希望下面的代码说明了这个场景.

public class MyObject {

    // Some properties and a location.
}

public class MyObjectSearch : MyObject {

    public double Distance { get; set; }

    public MyObjectSearch(MyObject obj) {
         base.Prop1 = obj.Prop1;
         base.Prop2 = obj.Prop2;
    }
}
Run Code Online (Sandbox Code Playgroud)

我的搜索功能:

public List<MyObjectSearch> DoSearch(Location loc) { 
  var myObjectSearchList = new List<MyObjectSearch>();       

   foreach (var object in myObjectList) {
       var distance = getDistance();
       var myObjectSearch = new MyObjectSearch(object);
       myObjectSearch.Distance = distance;
       myObjectSearchList.add(myObjectSearch);
   } 
   return myObjectSearchList;
Run Code Online (Sandbox Code Playgroud)

}

.net c# inheritance objectinstantiation

24
推荐指数
4
解决办法
3万
查看次数

使用多个查询条件查询Windows Azure表存储

我正在尝试查询Windows Azure存储中的表,并且最初TableQuery.CombineFiltersTableQuery<RecordEntity>().Where函数中使用如下:

TableQuery.CombineFilters(
    TableQuery.GenerateFilterCondition("PartitionKey",   QueryComparisons.GreaterThanOrEqual, lowDate),
    TableOperators.And,
    TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.LessThanOrEqual, lowDate),
    TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, entityId)
));
Run Code Online (Sandbox Code Playgroud)

不幸的是,CombineFilters最多只允许2个查询条件.所以我现在正在这样做:

var tableQuery = new TableQuery<RecordRowEntity>()
            .Where(TableQuery.CombineFilters("PartitionKey", string.Format("(PartitionKey ge '{0}') and (PartitionKey le '{1}') and (RowKey eq '{2}')", low, high, entityId));
Run Code Online (Sandbox Code Playgroud)

有没有其他方法可以做到这一点.我认为目前我正在这样做的方式很容易受到Azure Api工作方式的影响.

azure azure-table-storage data-partitioning

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

Azure表存储中的日期范围查询

您好问我的问题:Windows Azure表访问延迟分区键和行键选择有关我在Azure存储帐户中组织数据的方式.我有一个表存储方案,旨在存储有关实体的信息.

大约有4000到5000个实体.有6种实体类型,类型大致均匀分布.每个大约800'.

ParitionKey:entityType-Date

行键:entityId

作为问题的详细信息,我遇到了延迟问题,查询多个分区似乎需要一段时间.

基本上一种可能的解决方案是查询以下内容:

PartitionKey>'EntityType-Date'和PartitionKey <EntityType-HighDate'和RowKey ='EntityId'

这在Window Azure存储资源管理器中似乎不起作用.它似乎没有认识到大于小于,我有点期待.

我的问题究竟是什么比工作更少,更好,我会更好地按表格类型分割我的实体.因此我的查询将是?或者我应该采用不同的方法?

PartitionKey> LowDate和PartitionKey <HighDate和RowKey ='EntityId'

azure azure-table-storage data-partitioning

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

Leaflet JS Cluster Marker取消点击事件

我一直在努力取消单击传单中的群集时发生的单击事件。因此,当我点击一个集群图钉时,地图会放大。我希望出现一个自定义弹出窗口,或者至少有一些方法可以确保当我点击集群图钉时地图不会放大。

我尝试了各种我记得的技巧,例如

layerMakers.on('clusterclick', function(e) {
    e.originalEvent.preventDefault();
    e.originalEvent.stopPropagation();

    L.DomEvent.stopPropagation(e);
    return false;
});
Run Code Online (Sandbox Code Playgroud)

这是一个演示问题的小提琴。注意我已经省略了我所有的尝试,只是为了让它更容易玩。

http://jsfiddle.net/LzUkF/28/

任何答案都感激地收到。

html javascript maps leaflet

4
推荐指数
1
解决办法
905
查看次数

KnockoutJS将数组中的第一个元素绑定到div

的jsfiddle

我试图将数组的第一个元素绑定到div但它失败了.为什么约翰不会出现在div中?

<div data-bind="text: seedData[0].firstName"></div>
<select data-bind="options: seedData,
                        optionsText: 'firstName',
                        optionsValue: 'ID',
                        value: data.selectedValue">
</select>

var vm = {

    // Simulated seed data from server
    seedData: ko.observableArray([
    {
        ID: 1,
        firstName: 'John',
        value: '333'
    },
    {
        ID: 2,
        firstName: 'Bob',
        value: '333'
    },
    {
        ID: 3,
        firstName: 'Amy',
        value: '333'
    }]),

    // Simulated data from server
    data: {
        title: ko.observable('This is a sample'),
        selectedValue: ko.observable(2)
    }
};
ko.applyBindings(vm);
Run Code Online (Sandbox Code Playgroud)

javascript knockout.js

3
推荐指数
1
解决办法
3361
查看次数

我为什么要在每个文件上都要求所有模块?

我经常看到的默认方法是:

// repeat this in all files
var express  = require('express');
var mongoose = require('mongoose');
var async    = require('async');
...
Run Code Online (Sandbox Code Playgroud)

但在我的NodeJS应用程序中,我这样做:

// include this only on the server file
_express  = require('express');
_mongoose = require('mongoose');
_async    = require('async');
...
Run Code Online (Sandbox Code Playgroud)

我更喜欢使用_前缀来识别libs/modules而我不使用,var因为我不想在我的应用程序的每个文件上重复所有包的require/setup.

这样我require()只能在server.js文件上使用一次模块并在任何地方使用它.

这是一个坏主意吗?

javascript node.js

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

JS选择改变

我有一个用于选择的onchange功能.

$(document).ready(function() {
    $('#thechoices').on('change', do_the_change_studfac);
});

function do_the_change_studfac() {
    var the_position = $('#thechoices').val();
    var studentcourse = document.getElementById("studcourse");
    var atudentlevel = document.getElementById("studlevel");
    //var sub = $('#submithere');

    if (the_position == 'stud'){

        //alert('true');
        studentcourse.show();
        studentlevel.show();
        studentcourse.attr("required","required");
        studentlevel.attr("required","required");

    }
    if (the_position == 'fac'){

        //alert('false');
        studentcourse.hide();
        studentlevel.hide();
        studentcourse.removeAttr("required");
        studentlevel.removeAttr("required");


    }
}
Run Code Online (Sandbox Code Playgroud)

这些是我的html输入字段:

<label>Select Position</label>
<select id="thechoices" name="position">        
    <option value="stud">Student</option>
    <option value="fac">Faculty Member</option>
</select>

<label for="name">Name </label>
<input type="text" id="name" name="name" placeholder="Name" pattern="[a-zA-Z]+" required/>
<label>ID Number</label>
<input type="text" name="id_num" size="8" maxlength="8" pattern="\d" placeholder="8-digits only"required />
<label>Course</label> …
Run Code Online (Sandbox Code Playgroud)

javascript jquery input selection

0
推荐指数
1
解决办法
152
查看次数