小编Mr.*_*ith的帖子

如何将一个元素传递给循环中的jQuery帖子

我有以下代码:

for (_field in _fields) {
    $.post(
        '/api/fields',
        { id: _field.id },
        function(data, _field) {
            alert(data);
        } (data, _fields[_field)
    );
}
Run Code Online (Sandbox Code Playgroud)

我必须将_fields[_field]元素传递给从jQuery返回数据的函数,因为在循环期间丢失了对正确对象的引用.问题是,在定义post函数应该有一个_field参数时,您还必须为数据指定一个参数,否则数据将被覆盖_field.

目前数据返回,undefined因为我没有在循环内定义数据对象.我也试过传入null,但这也只是回归null.我正在寻找一种方法来传递元素而不会覆盖从post函数返回的数据.

有没有办法解决这个问题,或者是否有一种替代的jQuery方法可以满足需要?

javascript jquery post loops

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

在PHP中用数字填充数组的最快方法是什么?

使用PHP中的数字1-100填充数组的最快方法是什么?我想避免做这样的事情:

$numbers = '';

for($var i = 0; i <= 100; $i++) {
    $numbers = $i . ',';
}

$numberArray = $numbers.split(',');
Run Code Online (Sandbox Code Playgroud)

看起来既冗长又乏味,有更快的方法吗?

php arrays

3
推荐指数
2
解决办法
3100
查看次数

在C#中使用反射获取字段的属性

我写了一个从对象中提取字段的方法,如下所示:

private static string GetHTMLStatic(ref Object objectX, ref List<string> ExludeFields)
{
    Type objectType = objectX.GetType();
    FieldInfo[] fieldInfo = objectType.GetFields();

    foreach (FieldInfo field in fieldInfo)
    {
        if(!ExludeFields.Contains(field.Name))
        {
            DisplayOutput += GetHTMLAttributes(field);
        }                
    }

    return DisplayOutput;
}
Run Code Online (Sandbox Code Playgroud)

我班级中的每个字段也都有自己的属性,在这种情况下,我的属性称为HTMLAttributes.在foreach循环中,我试图获取每个字段的属性及其各自的值.它目前看起来像这样:

private static string GetHTMLAttributes(FieldInfo field)
{
    string AttributeOutput = string.Empty;

    HTMLAttributes[] htmlAttributes = field.GetCustomAttributes(typeof(HTMLAttributes), false);

    foreach (HTMLAttributes fa in htmlAttributes)
    {
        //Do stuff with the field's attributes here.
    }

    return AttributeOutput;
}
Run Code Online (Sandbox Code Playgroud)

我的属性类看起来像这样:

[AttributeUsage(AttributeTargets.Field,
                AllowMultiple = true)]
public class HTMLAttributes : System.Attribute
{
    public …
Run Code Online (Sandbox Code Playgroud)

c# reflection attributes fieldinfo

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

使用JavaScript/JQuery打开最大化新窗口的最快方法?

使用最适合大多数浏览器的JavaScript和/或JQuery 打开新窗口(最大化)最快方法是什么?

javascript windows jquery web

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

C++ 中的 BSTR 和 SysAllockStringByteLen()

我是 C++ 新手,所以这可能是一个菜鸟问题;我有以下功能:

#define SAFECOPYLEN(dest, src, maxlen)                               \
{                                                                    \
    strncpy_s(dest, maxlen, src, _TRUNCATE);                          \
    dest[maxlen-1] = '\0';                                            \
}

short _stdcall CreateCustomer(char* AccountNo)
{
    char tmpAccountNumber[9];
    SAFECOPYLEN(tmpAccountNumber, AccountNo, 9);
    BSTR strAccountNumber = SysAllocStringByteLen(tmpAccountNUmber, 9);

    //Continue with other stuff here.
}
Run Code Online (Sandbox Code Playgroud)

当我通过这段代码进行调试时,例如我传入了帐号“A101683”。当它做SysAllocStringByteLen()部分的时候,账号就变成了中文符号的组合...

任何人都可以对此有所了解?

.net c++ string chars visual-studio-2008

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

使用C#.NET 3.5的分布式监视服务

举例来说,假设您有5家使用相同平台(基于Windows)的公司都编写了自己的Web服务,那么您建议使用哪种技术使用C#和.Net 3.5来监视其所有不同的Web服务?

我的意图是构建一个向站点管理员提供有关服务状态的可视反馈的应用程序,当然还可以根据需要提供电子邮件/短信警报。您认为有最佳实践或方法可循吗?

另外,有没有我不知道的基于Windows的工具可以执行此操作?最好是开源的?

*编辑:想想最终结果,一个应用程序在跨不同公司运行的服务旁边仅显示红灯或绿灯。

公司1
     > Web服务1-绿色
     > Web服务2-绿色
公司2
     > Web服务1-红色
     > Web服务2-绿色

c# monitoring .net-3.5

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

使用C#使用字符数组修剪字符串

在字符串对象上使用Trim()方法时,可以向其传递一个字符数组,它将从字符串中删除这些字符,例如:

string strDOB = "1975-12-23     ";
MessageBox.Show(strDOB.Substring(2).Trim("- ".ToCharArray()));
Run Code Online (Sandbox Code Playgroud)

结果是"75-12-23"而不是预期的结果:"751223",这是为什么?

额外的问题:与这一行相比,哪一个会有更多的开销(它完全相同):

strDOB.Substring(2).Trim().Replace("-", "");
Run Code Online (Sandbox Code Playgroud)

c# string character-arrays

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

ASP.NET MVC - 使用C#将引用不同程序集的模型从Controller传递到View

给定两个组件:

project.web
project.lib

project.web程序集引用了包含一些业务逻辑的project.lib.来自project.lib的一个简单类:

public class Person
{
    public string Name;
}
Run Code Online (Sandbox Code Playgroud)

在project.web.Controllers中:

Using project.lib.models;

public class PersonController : Controller
{
    Person person = new Person();

    public ActionResult Index()
    {
        return View(person);
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我有一些问题的部分.在很多示例项目中,我在View中看到了以下内容(在本例中为Index.aspx):

<% @Import Namespace="project.lib.models" %>
Run Code Online (Sandbox Code Playgroud)

允许您像这样使用Model对象:

<%= Model.Name %>
Run Code Online (Sandbox Code Playgroud)

我没有像工作那样工作,我必须这样做:

<%= (Model as Person).Name %>
Run Code Online (Sandbox Code Playgroud)

要么

<%
    var person = (Person)Model;
    Response.Write(person.Name);
%>
Run Code Online (Sandbox Code Playgroud)

这是为什么呢?这种情况的原因是什么?评论?建议?我的类定义如下所示:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace project.lib.models
{
    public class Person
    {
        public Int64 PersonID;
        public string DisplayName;
        public …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc views models

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

Mousedown Timer使用JavaScript/jQuery

如何知道用户按住鼠标按钮的时间长度(网页上的任何位置)?我想在用户按住鼠标按钮至少2-3秒时执行一个功能(最好在此过程中取消鼠标按下).这可能吗?

javascript jquery mousedown

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

Opera和IE没有正确地归因于css文本修饰

使用Opera 11和IE 9,似乎这两个浏览器没有正确地归属CSS文本修饰样式.这在Chrome,FireFox和Safari中100%有效.有没有人建议如何解决这个问题?

错误的影响:

替代文字

正确的效果:

替代文字

这是CSS:

#main_title {
    font-size: 18px;
    color: #000;
    font-weight: bold;
}

#main_title a {
    color: #000;
}

#main_title_accent {
    border: 1px solid #000;
    background: #ff9935;
    text-decoration: none;
    font-size: 20px;
    padding: 5px;
}
Run Code Online (Sandbox Code Playgroud)

这是HTML:

<div id="main_title">
    <a href="home">Text <span id="main_title_accent">Goes</span> Here</a>
</div>
Run Code Online (Sandbox Code Playgroud)

html css layout opera internet-explorer

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

if语句行为的一行说明?

示例代码:

int hour = 0;
bool saveData = true;

if(hour > 0) doSomeMethod(); saveData = false;
Run Code Online (Sandbox Code Playgroud)

在上面的代码中,saveData将始终设置为false,但不会触发doSomeMethod().我认为编译器将doSomeMethod()之后的分号视为移动到下一个语句的指示符,忽略它与if语句位于同一行.这种行为的原因是什么?

c# behavior

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