访问范围中指定的对象的内部值

时间:2017-07-14 07:42:31

标签: javascript angularjs arrays object angularjs-scope

我想从我的对象中控制日志记录值,但它返回一个未定义的值。

$scope.sidsamp = [{todoText:'Clean House', done:false}];

    $scope.todoAdd = function() {
        $scope.sidsamp.push({todoText:$scope.todoInput, done:false});
        $scope.todoInput = "";
        console.log($scope.sidsamp.todoText);
    };

我想在控制台中显示todoText的值。我怎么可能这样做?

2 个答案:

答案 0 :(得分:1)

这很简单..

因为private Program() { const string address = "tcp://localhost:5000"; var socket = new DealerSocket(); socket.Options.SendHighWatermark = 1; socket.Options.Identity = Encoding.ASCII.GetBytes(Guid.NewGuid().ToString("N")); socket.Connect(address); var poller = new NetMQPoller(); poller.Add(socket); socket.SendReady += OnSendReady; poller.RunAsync(); Thread.Sleep(5000); Console.WriteLine("Disposing"); poller.Dispose(); // get stuck on this one Console.WriteLine("Disposed"); } private void OnSendReady(object sender, NetMQSocketEventArgs e) { Console.WriteLine("0"); e.Socket.SendFrame("hello"); Console.WriteLine("1"); e.Socket.SendFrame("hello"); // this will block Console.WriteLine("2"); } 是一个数组,所以您无法直接访问其值。您可以使用循环来访问它。

以下是更新的代码。

$scope.sidsamp

答案 1 :(得分:0)

因为sidsamp是一个数组,所以你需要使用索引访问数组内的元素;

$scope.sidsamp = [{todoText:'Clean House', done:false}];

$scope.todoAdd = function() {
    $scope.sidsamp.push({todoText:$scope.todoInput, done:false});
    $scope.todoInput = "";
    console.log($scope.sidsamp[0].todoText);
};