小编dtg*_*dtg的帖子

Angular 1.2.1中的$ setPristine()方法似乎没有按预期工作

我正在尝试使用$setPristineAngularJS中的函数重置文本框,但它似乎不会导致所需的行为.

我的表单看起来像这样:

<form name="addInviteForm" ng-controller="InviteCtrl" ng-submit="sendInvitation(userEmail)">

      Pristine? {{addInviteForm.$pristine}}

      <!-- email input -->
      <div>
        <input type="email" name="email" ng-model="userEmail" placeholder="Enter email here"  class="line-item-input see" required>
        <span class="error" ng-show="addInviteForm.email.$error.email" style="color:red">Invalid Email</span>
      </div>

      <!-- submit button -->
      <input type="submit" name="send" class="btn btn-success center" value="Send Invitation">
</form>
Run Code Online (Sandbox Code Playgroud)

和我的控制器中的相应代码:

$scope.sendInvitation = function(userEmail) {

        // do some work here ...

        // hmm, this doesn't seem to work ...
        $scope.addInviteForm.$setPristine();
    };
Run Code Online (Sandbox Code Playgroud)

虽然表单显示$pristine设置为true表单条目,然后设置为false在文本框中输入数据时,在提交表单后它确实显示$pristine设置为true ....然而文本框中的值仍然为它是在按下提交按钮之前.

我在这里错过了什么?

javascript dom angularjs

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

基于 Clojure 类型的比较

我正在尝试测试以下记录类型:

(defrecord FirstOrderState [datum matrix]
  State
  ;; implementation goes here ...
  )
Run Code Online (Sandbox Code Playgroud)

我正在尝试根据上述类型进行分支,但没有得到我需要的结果

(def state (->FirstOrderState datum matrix))

(= (type state) composer.algorithm.markov.state.FirstOrderState)
=> false
Run Code Online (Sandbox Code Playgroud)

但是,查看 的类型state确认它应该匹配:

(type state)
=> composer.algorithm.markov.state.FirstOrderState
Run Code Online (Sandbox Code Playgroud)

这似乎应该有效,因为类似的检查结果如下true

(= (type []) clojure.lang.PersistentVector)
=> true
Run Code Online (Sandbox Code Playgroud)

我在这里缺少什么?使用下面的 hack 提供了一个解决方案,但不是很优雅:

(= (str (type state)) (str composer.algorithm.markov.state.FirstOrderState))
=> true
Run Code Online (Sandbox Code Playgroud)

functional-programming clojure predicates

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

SML错误:当将列表中的整数与整数进行比较时,运算符和操作数不一致

我是标准ML的新手,无法弄清楚为什么我会遇到此类型不匹配错误:

fun number_in_month (month : int, dates : int list) =                                            
    if null dates                                                                                
    then 0                                                                                       
    else if (month = (hd (tl (hd dates))))            
    then number_in_month(month, (tl dates)) + 1
    else number_in_month(month, (tl dates))
Run Code Online (Sandbox Code Playgroud)

评估此函数会导致以下错误:

Error: operator and operand don't agree [tycon mismatch]     
 5  operator domain: 'Z list                                                                       
 6  operand:         int                                                                           
 7  in expression:                                                                                 
 8    tl (hd dates)     
Run Code Online (Sandbox Code Playgroud)

但是,在REPL中,如果我执行以下操作:

val x = [[84, 12, 23], [83, 01, 18]]
12 = (hd (tl (hd x)))                    (*  -> val it = true …
Run Code Online (Sandbox Code Playgroud)

sml typechecking

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

可以使用泛型类型实例化List <T>吗?

我正在辅导的一个学生正在参加一个Web开发课程,该课程使用了关于Java的Dietel书籍,其中包含了一些涉及泛型的奇怪代码:

class StackComposition <T>
{
    private List<T> stackList;

    public StackComposition()
    {
        stackList = new List<T>("stack")  // ERROR
    }

    // .... more code
}
Run Code Online (Sandbox Code Playgroud)

很明显,为什么这段代码不起作用,我很困惑为什么教师建议学生使用这段代码作为起点.也许我只是不理解泛型,我的Java技能不足,但我没有看到如何用泛型类型实例化泛型集合.我看到的目的是通过使用通用List集合并在运行时确定类型来创建Stack,但我不知道如何使用上面的配置.我的第一个倾向是告诉学生使用Generic Stack<T>对象并忘记编写这个自定义Stack类,但显然这不是作业的目标.

我尝试使用java.lang.reflect包来解决这个问题,但据我所知,这只适用于非通用容器,例如Array:

public StackComposition(Class<T> type)
{
    Object obj = Array.newInstance(type, 10);
}
Run Code Online (Sandbox Code Playgroud)

java generics objectinstantiation

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