Странный сброс переменных в JavaScript

При звонке console.dir(myVariable)Я получил этот странный результат:

JS: === dump(): dumping function and properties names  ===                                                                          
JS: 0:  [                                                                                                                           
JS: 1: o                                                                                                                           
JS: 2: b                                                                                                                           
JS: 3: j                                                                                                                           
JS: 4: e                                                                                                                           
JS: 5: c                                                                                                                           
JS: 6: t                                                                                                                           
JS: 7:                                                                                                                             
JS: 8: O                                                                                                                           
JS: 9: b                                                                                                                           
JS: 10: j                                                                                                                          
JS: 11: e                                                                                                                          
JS: 12: c                                                                                                                          
JS: 13: t 
JS: 14: ]
JS: === dump(): finished ===          

Что это значит? Почему я не получил стандартный вывод объекта или массива?

Обратите внимание, что я не смог использовать инструмент разработки Chrome / Firefox, так как я пишу код из среды Telerik NativeScript.

Также я называю этот код из Code-Behind для компонента, встроенного в Angular 2.

Это HTML-код для компонента проводника explorer.html:

<ActionBar title="{{ 'activity_explorer' | L }}" android.icon="res://icon"
    android.iconVisibilty="always">
    <ActionItem icon="res://icon_plus" text="{{'menuitem_new' | L}}" (tap)="showMenuItemNew()"></ActionItem>
    <ActionItem [icon]="selectionModeIcon()" text="selectionModeItemText()" (tap)="toggleSelectionMode()"></ActionItem>
</ActionBar>

<GridLayout rows="1*, 12*" modal-dialog-host>

    <Label class="path_component" row="0" [text]="_path" textWrap="true"> </Label>

    <ListView row="1" [items]="_files">
        <template let-item="item">
            <loloof64-explorer-item-line [checkboxVisible]="_selectionMode" item="{{item}}"></loloof64-explorer-item-line>
        </template>
    </ListView>

 </GridLayout>

Это HTML для компонента explorer_item_line: explorer_item_line.html

<GridLayout columns="1*, 1*, 7*">
    <loloof64-checkbox #check_comp col="0" [visible]="checkboxVisible"> </loloof64-checkbox>
    <Image col="1"  (tap)="handleTap()" src="res://folder"></Image>
    <Label col="2"  (tap)="handleTap()" text="Text" textWrap="true">   </Label>
</GridLayout>

Это класс ExploreItem:

export class ExplorerItem {

    private _name: string;
    private _isDirectory: boolean;

    constructor(name: string, isDirectory: boolean){
        this._name = name;
        this._isDirectory = isDirectory;
    }

    name(){
        return this._name;
    }

    isDirectory(){
        return this._isDirectory;
    }

    public isParent() : boolean {
        return this._name === ".." && this._isDirectory;
    }

    public static sort(left: ExplorerItem, right: ExplorerItem): number {
        if (left.isDirectory() === right.isDirectory()) { 
            return left.name().toLowerCase().localeCompare(right.name().toLowerCase());
        }
        else {
            return left.isDirectory() ? -1 : 1;
        }
    }
}

Это explorer_item_line.ts:

import {Component, Input, ViewChild} from '@angular/core';
import {Checkbox} from "../checkbox/checkbox";
import {ExplorerItem} from "./explorer_item";

import * as _ from 'lodash';

@Component({
    moduleId: module.id,
    selector: 'loloof64-explorer-item-line',
    templateUrl: 'explorer_item_line.html',
    styleUrls: ['explorer_item_line.css'],
    directives: [Checkbox]
})
export class ExplorerItemLine {
    @Input() checkboxVisible: boolean = false;
    @Input() item: any;
    @ViewChild('check_comp') checkboxComp: Checkbox;

    handleTap(){
        if (this.checkboxVisible){
            this.checkboxComp.checked = ! this.checkboxComp.checked;
        }

        console.log(JSON.stringify(this.item))
    }
}

Я думаю, что это проблема связывания между компонентами explorer и explorer_item_line, но я не могу понять, почему и как ее решить.

И, наконец, я попадаю на страницу отладки Nativescript: так что я должен иметь возможность проверить ее в инструменте разработчика Chrome.

1 ответ

Решение

item="{{item}} является синтаксисом для привязки ядра NativeScript. где NativeScript+Angular-2, вы должны использовать стиль ng, что означает [item]="item" Использование основного синтаксиса в ng-app приведет к тому, что возвращаемое значение будет иметь вид [object Object] вместо того значения, которое вы ожидаете.

Другие вопросы по тегам