小编Ram*_*feh的帖子

AngularJS控制器和方法

我是angularjs的初学者,有一些关于控制器的问题.
这是我的示例控制器:

function exampleController($scope)
{
   $scope.sampleArray = new Array();

   $scope.firstMethod = function()
   {
      //initialize the sampleArray
   };

   $scope.secondMethod = function()
   {
      this.firstMethod();
   };
};
Run Code Online (Sandbox Code Playgroud)

这是我的问题:

  • 我怎么能叫firstMethodsecondMethod?我的方式是正确的,还是更好的方式?
  • 我如何为控制器创建构造函数?我需要调用调用初始化sampleArray的firstMethod的secondMethod?
  • 如何从html代码调用特定方法?我发现ng-initialize但我无法弄清楚如何使用它.

javascript angularjs

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

如何将XML转换为Dictionary

我的xml如下:

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <data name="LogIn">Log In</data>
  <data name="Password">Password</data>
</root>
Run Code Online (Sandbox Code Playgroud)

我没有Linq成功做到这一点,任何人都可以帮我将以下代码转换为Linq:

using (XmlReader reader = XmlReader.Create(_xml))
{
    while (reader.Read())
    {
       if (reader.NodeType == XmlNodeType.Element && reader.LocalName == "data")
       {
          reader.MoveToAttribute("name");
          string key = reader.Value;
          reader.MoveToContent();
          string value = reader.ReadElementContentAsString();
          _dictionary.Add(key, value);
       }
    }
    reader.Close();
}
Run Code Online (Sandbox Code Playgroud)

c# xml linq linq-to-xml

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

在typescript中获取类的属性

我有以下课程:

export class Test {

        private _rowsCount: string;
        public get RowsCount(): string {
            return this._rowsCount;
        };
        public set RowsCount(value: string) {
            this._rowsCount = value;
        };

        private _rowsCount2: string;
        public get RowsCount2(): string {
            return this._rowsCount2;
        };
        public set RowsCount2(value: string) {
            this._rowsCount2 = value;
        };
    }
Run Code Online (Sandbox Code Playgroud)

我需要迭代特定类中的属性,我尝试了以下内容:

Object.keys(this).forEach((key)=> {
    console.log(key);
});
Run Code Online (Sandbox Code Playgroud)

但是这个问题只是在private字段上进行迭代,我也尝试了以下我得到了所有的methodsproperties:

    for (var property in this) {
        if (this.hasOwnProperty(property)) {
            console.log(property);                
        }
    }
Run Code Online (Sandbox Code Playgroud)

有没有人有办法解决吗?

谢谢!

javascript typescript

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

在子div中也可以在父div中单击

我有以下代码:

        <table class="table">
            <tr>
                <th>Name___</th>
            </tr>
            <tr ng-repeat="app in apps"
                ng-click="go('/editApp/' + plugin.name);">

                <td>
                    <span>{{app.name}}</span>
                </td>
                <td style="width: 100px;">
                    <i class="glyphicon glyphicon-pencil" 
                              ng-click="openPopup(app)"></i>
                </td>
            </tr>
        </table>
Run Code Online (Sandbox Code Playgroud)

当我点击OpenPopup时,go()方法也会触发,我怎么能这样做,如果我点击弹出窗口就会触发弹出窗口?

javascript html5 twitter-bootstrap angularjs

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

在javascript或angularjs中解析url

我试图在javascript中解析url,我找到了以下方法:

var getLocation = function(href) {
    var l = document.createElement("a");
    l.href = href;
    return l;
};
var l = getLocation("http://example.com:3000/path");
var host = l.host; // example.com
var port = l.port; // 3000
Run Code Online (Sandbox Code Playgroud)

但是如果这些地方我遇到了问题:

http://TLVS0015:3000/cti/YTest // the parse found the port, but its not found the host

http://ctmwe:80/ReportServer/ReportService2010.asmx // the parse found the host, but don't found the port
Run Code Online (Sandbox Code Playgroud)

还有其他方法可以解析吗?

javascript url parsing angularjs

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

如何修复表单控件的宽度?

我在HTML中有以下代码:

<div class="col-sm-12">
  <div ng-repeat="param in plugin.wsdlURLs track by $index" class="col-sm-12">
    <select class="form-control col-sm-4" ng-model="test" ng-options="lOrU for lOrU in localOrUrl">
    </select>
    <input type="url" class="form-control col-sm-8 invalidInput">
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

我遇到了一个问题,当我放一个form-control类时,它将显示select在一行中,而input在另一行中.我想保留form-control课程,selectinput在同一行显示.我知道问题来自于form-control,因为宽度是100%

css html5 twitter-bootstrap angular-ui-bootstrap twitter-bootstrap-3

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

如何在C#中改进get调用方法的代码

我们有一个"logger"类,它具有获取日志消息的log方法,并将消息和调用方法写入日志,首先我们还要将以下内容发送给log方法新参数Method.Base.GetCurrentMethod().我找到了另一种方法,使用Relection.MethodBase:

public void Log(string message)
{
   stackTrace = new StackTrace();
   string methodName = stackTrace.GetFrame(1).GetMethod().Name;
   ....
}
Run Code Online (Sandbox Code Playgroud)

但我有一个问题,每次调用log方法,我都被迫创建新实例StackTrace,当我尝试在构造函数中创建实例时,我得到方法名称InvokeMethod.

我们在项目中使用MEF.任何想法如何改进代码?

c# mef stack-trace silverlight-5.0

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

将string []转换为ObservableCollection <string>

我有一个string[].我想做的是转换string[]ObservableCollection<string>.

.net c# casting observablecollection c#-4.0

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