小编iro*_*rom的帖子

ng-pattern不显示$ error.pattern

我在这里有脚本,ng-pattern工作正常,因为只有输入匹配模式后,才会在输出中显示scope.subnet.但是如果ng-pattern不匹配,ng-show不会显示任何错误

<body ng-contoller="myConfigGenCtr">
  <form novalidate name="myForm">
            <div class="form-group">
                <label for="hostname">Firewall hostname</label>
                <input type="text" ng-model="hostname" class="form-control" id="hostname">
            </div>
            <div class="form-group">
                <label for="subnet">Firewall subnet</label>
                <input type="text" ng-model="subnet" class="form-control" id="subnet"
                       required ng-pattern="/^(?:[0-9]{1,3}\.){3}/" >
                <div class="custom-error"  ng-show="myForm.subnet.$error.pattern">
                    Not a valid subnet, should be i.e. 10.x.y. (3 bytes only)</div>
            </div>
        </form>
  <div>Output: {{subnet}}</div>      
</body>
Run Code Online (Sandbox Code Playgroud)

javascript forms validation angularjs angularjs-forms

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

如何在不使用CURL的情况下运行HTTP请求

我有基于arm的busybox(嵌入式Linux)与有限的二进制文件如何http发布或放置而不使用curl?

curl busybox

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

如何在React中编写和读取组件状态?

我有MyComponent使用setData()在state中写入数据,getData()用于读取状态.这是React的最佳实践吗?它对我来说很好,但不确定我做的是最简单的方法,请建议

class MyComponent extends Component {
  constructor(props) {
    super(props);
    this.state = {
      data: []
    };

  }

  setData(){    
    this.setState({data:"123"});   
  }

  getData() {
    console.log(this.state.data); // 123 OK !!!   
  }

  componentDidMount() {    
    this.setData();  

  }
  componentDidUpdate() { 
    this.getData();
  }
  render() {
    return (                     
       <div>           
          {this.state.data} // 123 OK !!!
       </div>                        
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

reactjs

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

如何修改golang中的struct字段

我有例子play.golang.org/p/Y1KX-t5Sj9我在struct User上定义方法Modify()

type User struct {
  Name string
  Age int
}
func (u *User) Modify() {
  *u = User{Name: "Paul"}
}
Run Code Online (Sandbox Code Playgroud)

在main()中我定义了struct literal &User {Name:"Leto",Age:11}然后调用u.Modify().这导致打印' 保罗0 '我喜欢结构字段名称已更改,但保持Age字段的正确方法是什么?

struct go

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

如何编写 Kusto 查询以在一张表中获取结果?

我有 2 个 KQL 查询,我想将它们组合起来以将两行显示为一个结果。不仅仅是第一次查询的结果,然后是第二次查询的结果:

R_CL
| where isnotempty(SrcIP_s) 
| project Message 
| take 1;

R_CL
| where isempty(SrcIP_s) 
| project Message 
| take 1
Run Code Online (Sandbox Code Playgroud)

请参阅下面的示例R_L。我想看到 2 行作为结果,一个 SrcIP_s 不为空,第二个 SrcIP_s 为空(在这种情况下,它总是相同的)

let R_CL = datatable ( SrcIP_s:string, Message:string)
["1.1.1.1" ,"one",
"" ,"two",
"2.2.2.2","three",
"3.3.3.3","four"];
R_CL
| project SrcIP_s, Message
Run Code Online (Sandbox Code Playgroud)

kql azure-data-explorer

6
推荐指数
2
解决办法
8587
查看次数

forEach循环内的JavaScript变量作用域

在下面的代码中,与forEach循环一起使用的回调函数遍历返回的结果。forEach循环中的变量“错误”和回调中的“错误”是否相同?

session.getAll(options, function (error, varbinds) {
    varbinds.forEach(function (vb) {
        if (error) 
            console.log('getALL Fail ');
        else              
            console.log(vb.value);            
    });
});
Run Code Online (Sandbox Code Playgroud)

javascript scope

5
推荐指数
2
解决办法
9621
查看次数

如何在React中传递函数作为道具?

我有功能组件GetWeather,我希望将GetLocation函数的结果作为道具传递,基于GetWetaher将执行某些操作,即另一个获取请求(在下面的示例中,它仅渲染其道具).我认为它必须在ComponentDidMount内部发生,不知道如何做到这一点

    function GetLocation() {
        axios.get('http://ipinfo.io')
          .then((res) => {      
            return res.data.loc;
          })

      }
    function GetWeather(props) {
    //more code here, including another get request, based on props
        return <h1>Location: {props.location}</h1>;    
    }

    class LocalWeather extends Component {           
      componentDidMount() {    
        //???     
      }          
      render() {
        return (
          <div >                         
                <GetWeather location={GetLocation}/> //???                                               
          </div> 
        );
      }
    }
Run Code Online (Sandbox Code Playgroud)

更新:所以根据Damian的建议,下面的内容对我有用

function GetWeather(props) {   
    return <h3>Location: {props.location}</h3>;   
}

class LocalWeather extends Component {
  constructor(props) {
    super(props);
    this.state = {
      location: []
    }; 
  }
  getLocation() {
    axios.get('http://ipinfo.io')
      .then((res) => …
Run Code Online (Sandbox Code Playgroud)

reactjs

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

在python中提取xml标签之间的文本

我在下面有 xml 字符串,并尝试在每个条目标签的标签域、接收时间、序列和序列号之间打印文本。

xml="""
<response status="success" code="19"><result><msg><line>query job enqueued with jobid 19032</line></msg><job>19032</job></result></response>
19032
<response status="success"><result>
  <job>
    <tenq>14:10:09</tenq>
    <tdeq>14:10:09</tdeq>
    <tlast>19:00:00</tlast>
    <status>ACT</status>
    <id>19032</id>
    <cached-logs>64</cached-logs>
  </job>
  <log>
    <logs count="20" progress="29">
      <entry logid="2473601">
        <domain>1</domain>
        <receive_time>2017/11/26 14:10:08</receive_time>
        <serial>007901004140</serial>
        <seqno>10156449120</seqno>
      </entry>
      <entry logid="2473601">
        <domain>1</domain>
        <receive_time>2017/11/26 14:10:08</receive_time>
        <serial>007901004140</serial>
        <seqno>10156449120</seqno>
      </entry>
      </logs>
  </log>
</result></response>
"""
Run Code Online (Sandbox Code Playgroud)

使用 xml.etree.ElementTree。为了获得标签之间的内容,我正在尝试node.attrib.get('domain')node.get('domain') ..请告知

import xml.etree.ElementTree as ET
tree = ET.fromstring(xml)
for node in tree.iter('entry'):
        print node
Run Code Online (Sandbox Code Playgroud)

它也可以是其他 python 库,不必是 xml.etree。我不想盲目地在标签之间打印文本,我需要打印标签名称后跟文本,例如:

domain: 1 …
Run Code Online (Sandbox Code Playgroud)

python xml

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

如何在Go中解决模糊选择器

我定义了两个结构类型Type1和Type2

type Type1 struct {
A1,B1,C1 string
}
type Type2 struct {
A1,B1 string
}
Run Code Online (Sandbox Code Playgroud)

将它们嵌入到struct type Supertype中

type Supertype struct {
    Type1
    Type2
}
Run Code Online (Sandbox Code Playgroud)

然后使用方法Send定义接口Sender,以便同时用于Type1和Type2

type Sender interface {
    Send() 
}
Run Code Online (Sandbox Code Playgroud)

最后,我定义了func,我想引用Type1和Type2字段

func (p Supertype) Send() {
..
p.A1 = "foo"
..

}
Run Code Online (Sandbox Code Playgroud)

当然得到'模棱两可的选择器p.A1'错误.如何使用方法发送两种结构类型Type1和Type2?有类似的问题两个不同类型如何在golang中使用接口实现相同的方法?但我不认为它适用于我的情况

struct interface go

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

提供者变量是否可以在 terraform 中使用?

仍然无法在 Terraform v0.12.6 中使用变量提供程序吗?在 *.tfvars 中,我列出了变量 供应商

supplier = ["azurerm.core-prod","azurerm.core-nonprod"]
Run Code Online (Sandbox Code Playgroud)

和 provider.tf 中定义的提供者:

provider "azurerm" {
  ...
  alias           = "core-prod"
}

provider "azurerm" {
  ...
  alias = "core-nonprod"
Run Code Online (Sandbox Code Playgroud)

然后我想在 *.tf 中引用它。下面的例子是“数据”,但同样适用于“资源”

data "azurerm_public_ip" "pip" {
  count = "${var.count}"
   ....
   provider = "${var.supplier[count.index]}"
} 
Run Code Online (Sandbox Code Playgroud)

什么是解决方法?错误:无效的提供者配置引用,显示提供者参数需要提供者类型名称,可选后跟一个句点,然后是配置别名

terraform terraform-provider-azure

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