首页 \ 问答 \ AngularJS - 为什么我无法实时更新我的数组长度?(AngularJS - Why can't I get my array length updated in real-time?)

AngularJS - 为什么我无法实时更新我的数组长度?(AngularJS - Why can't I get my array length updated in real-time?)

我正在使用AngularJSFirebase填充一个简单的待办事项笔记应用程序。 (而且我也是AngularJS的新手!)To-do笔记将保存在$scope.todos变量中。 这是我的app.js代码:

myApp.controller('mainController', function($scope, $firebase) {
    // connect to firebase
    var ref = new Firebase("https://XXX.firebaseio.com/todos");
    var fb = $firebase(ref);
    $scope.todos = [];
    // sync as object
    var syncObject = fb.$asObject();
    // 3-way data binding
    syncObject.$bindTo($scope, "todos");

    $scope.addNewTodo = function(){
        var todoTitle = $(".add-todo").val();
        var createdAt = new Date();
        var element = {
            title: todoTitle,
            timestamp: createdAt,
            done: false
        };
        fb.$push(element);
        $(".add-todo").val("");
    };
});

这是我的index.html代码:

<div class="container" ng-app="todoApp" ng-controller="mainController">
    <div class="row">
        <div class="col-md-6">
            <div class="todolist not-done">
                <h1>Todos</h1>
                <input type="text" class="form-control add-todo" placeholder="Add todo" ng-enter="addNewTodo()">
                <button id="checkAll" class="btn btn-success">Mark all as done</button>
                <hr/>
                <ul id="sortable" class="list-unstyled" ng-repeat="todo in todos">
                    <li class="ui-state-default">
                        <div class="checkbox">
                            <label>
                            <input type="checkbox" value=""/> {{ todo.title }}</label>
                        </div>
                    </li>
                </ul>
                <div class="todo-footer">
                    <strong><span class="count-todos">{{ todos.length }}</span></strong> Items Left
                </div>
            </div>
        </div>
    </div>
</div>

我添加了{{todos.length}}来计算$scope.todos数组中剩余的todos元素。 但是当我添加或删除$scope.todos数组中的元素时,它不会自动更新。 这对我来说有点奇怪,因为它与MeteorJS完全不同,如果我做同样的事情。


I'm populating a simple To-do notes application using AngularJS and Firebase. (And I'm new to AngularJS, too !) The To-do notes will be saved in $scope.todos variable. This is my app.js code:

myApp.controller('mainController', function($scope, $firebase) {
    // connect to firebase
    var ref = new Firebase("https://XXX.firebaseio.com/todos");
    var fb = $firebase(ref);
    $scope.todos = [];
    // sync as object
    var syncObject = fb.$asObject();
    // 3-way data binding
    syncObject.$bindTo($scope, "todos");

    $scope.addNewTodo = function(){
        var todoTitle = $(".add-todo").val();
        var createdAt = new Date();
        var element = {
            title: todoTitle,
            timestamp: createdAt,
            done: false
        };
        fb.$push(element);
        $(".add-todo").val("");
    };
});

And this is my index.html code:

<div class="container" ng-app="todoApp" ng-controller="mainController">
    <div class="row">
        <div class="col-md-6">
            <div class="todolist not-done">
                <h1>Todos</h1>
                <input type="text" class="form-control add-todo" placeholder="Add todo" ng-enter="addNewTodo()">
                <button id="checkAll" class="btn btn-success">Mark all as done</button>
                <hr/>
                <ul id="sortable" class="list-unstyled" ng-repeat="todo in todos">
                    <li class="ui-state-default">
                        <div class="checkbox">
                            <label>
                            <input type="checkbox" value=""/> {{ todo.title }}</label>
                        </div>
                    </li>
                </ul>
                <div class="todo-footer">
                    <strong><span class="count-todos">{{ todos.length }}</span></strong> Items Left
                </div>
            </div>
        </div>
    </div>
</div>

I added {{todos.length}} for counting the remaining todos elements in the $scope.todos array. But it isn't automatically updated when I add or remove elements from the $scope.todos array. This is a bit strange for me cause it's quite different than what MeteorJS does, if I do the same thing.


原文:https://stackoverflow.com/questions/27665912
更新时间:2022-10-28 21:10

最满意答案

试试这个 - 那是你以后的样子吗?

%let mydt = 06/30/1999;

%let mydt2  = %sysfunc(inputn(&mydt,mmddyy10.));

%put &mydt2;

Try this - is that what you were after?

%let mydt = 06/30/1999;

%let mydt2  = %sysfunc(inputn(&mydt,mmddyy10.));

%put &mydt2;

相关问答

更多
  • 要准确匹配默认日期时间结构的SAS输出,您需要使用as.POSIXct,如注释中所述,另外使用tz = UTC参数: sasDateTimes <- c(1706835972, 1716835972, 1726835972, 1736835972, 1746835972, 1756835972, 1766835972, 1776835972, 1786835972, 1796835972, 1806835972, 1816835972, 1826835972, 1836835972, 184683597 ...
  • 您可能需要使用不同的信息来读取字符日期,以便SAS可以将它们解释为数字(因为SAS中的日期实际上是数字值),然后将它们格式化为MMYYS. 。 这已经过测试,适用于我: DATA temps; FORMAT newdate MMYYS.; SET indata; newdate = INPUT(COMPRESS('01/'||date),DDMMYY10.); RUN; You may have to use a different informat to read in the character da ...
  • SAS中的日期值(正确保存时)存储为整数,即自1960年1月1日以来的整数天数。 所以今天是20230 。 然后格式告诉SAS打印整齐时应该是什么样子; 和信息告诉SAS如何将整齐打印的日期翻译成这个数字。 在你的例子中, mmddyy10. 是一个信息告诉SAS采取05/22/2015并将其转为20230 。 欢迎您与DATE9进行比较。 格式化为此日期值:因为两者都将存储为整数。 它们在屏幕上的外观与人类相关,但整数与SAS相关。 Date values in SAS (when saved corre ...
  • format会影响SAS显示变量值的方式。 它不会影响实际值本身。 因此,假设变量CREATION_DATE是日期时间值,只需为其指定DATETIME20格式即可。 显示是你想要的: proc sql; create table data.test as select ID, CREATION_DATE format=datetime20. from connection to odbc ( select ID, DATE AS CREATION_DATE from m ...
  • 也许直接的CDate方法对您CDate ,因为您的系统和Excel语言似乎是英语。 对我来说,它不起作用,因为我的系统不知道英文月份名称。 所以我必须用数字真正地替换它们: Sub MonthReplace() Dim i As Long Dim monthArray As Variant Dim c As Range Dim strDate As String monthArray = Array("January", "February", "March", ...
  • 试试这个 - 那是你以后的样子吗? %let mydt = 06/30/1999; %let mydt2 = %sysfunc(inputn(&mydt,mmddyy10.)); %put &mydt2; Try this - is that what you were after? %let mydt = 06/30/1999; %let mydt2 = %sysfunc(inputn(&mydt,mmddyy10.)); %put &mydt2;
  • 使用input()函数和适当的信息: datevariable=input(textvariable,ddmmyy10.); Use the input() function with an appropriate informat: datevariable=input(textvariable,ddmmyy10.);
  • 我不相信你可以使用Picture创建INformats; 只有格式。 (INformat =获取字符串并转换为(在本例中)日期值,格式=获取日期值并转换为字符串。) 幸运的是,ANYDTDTM。 似乎很好地读了这个。 (我改为上午11点以确保时间部分没问题。) data test; input @1 x ANYDTDTM19.; put x= DATETIME17.; datalines; Mar 20 2013 11:00AM ;;;; run; I do not believe you can cre ...
  • 使用%sysfunc函数很方便: %LET P_YEAR = %SYSFUNC(YEAR(%SYSFUNC(TODAY())+29)); %LET P_MONTH = %SYSFUNC(MONTH(%SYSFUNC(TODAY())+29)); %PUT &P_YEAR &P_MONTH; 结果是: 2016 2 编辑 (请先尝试自己解决,但这里有一个完整的解决方案...) data _null_; target = today() + 29; format target YYMMDDS10.; ...
  • 在使用input时,不需要使用put语句将值转换为numeric。 input的目标是获取字符输入并将其转换为数字值,以便SAS进行数学运算。 我多么记得它: 在 put中:将输入值转换为数值 Put :Out 将数值作为字符值 您可以尝试使用anydtdte.更简单的解决方案anydtdte. 信息 。 它能够读取以下任何信息: 日期 约会时间 DDMMYY JULIAN MDYAMPM MMDDYY MMxYY MONYY 时间 YMDDTTM YYMMDD YYQ YYxMM 月日年 例如: %let ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。