[英]Strange javascript variable dumping
當調用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 ===
這是什么意思 ? 為什么我沒有得到標准的對象或數組輸出?
請注意,由於我是從Telerik NativeScript框架進行編碼,因此無法使用chrome / firefox開發工具。
我也從Angular 2中內置的組件的“隱藏代碼”中調用此代碼。
這是Explorer組件的explorer.html的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>
這是explorer_item_line組件的HTML: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_item_line組件之間的綁定問題,但是我無法弄清楚為什么以及如何解決它。
最后,我進入了Nativescript調試頁面:因此,我應該能夠在Chrome的開發者工具中對其進行檢查。
item="{{item}}
是NativeScript核心綁定的語法..其中NativeScript + Angular-2您應該使用ng-style,這意味着[item]="item"
在ng-app中使用核心語法會導致該值返回的類型為[object Object]
而不是您期望的值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.