問題は、このコード行から来ている。は取得「はエラー.find()メソッドの使用
const t: GridType = gridDef.find(a => { a.GridName == core.GridStyle; return a; });
私は取得していますエラー「ブール値に対するボイド割り当てられないが、この
ERRORであります(このvoid:a:GridType)=> voidの引数は の型には割り当てられません。ype 'src/app/grid-builder/builder-scratch.ts(255,43):エラーTS2345: (void:void、value:GridType、index:number、obj:GridType [])=>ブール値 ' ' void '型は' bo '型に代入できませんオレアン '。
これまでのように、グリッドを動的に作成するために、角型コンポーネントに拡張するクラスを定義しています。私たちは、私がしようとしているものをconstructor
constructor() {
this.Settings.GridStyle = 'SiteGridA';
this.GridData = GridDefs;
this.buildGrid(this.Settings, this.GridData);
}
に戻って焦点を当てている場合、この
export interface GridType {
GridName : string;
Columns : GridLine[];
Rows : GridLine[];
}
//other interfaces chaining into it
export interface GridLine {
Names : LineName[];
Type : string;
CalcType : string;
CSize : CellSize;
}
export interface LineName { Name: string; }
export interface CellSize {
Size? : number;
Repeat? : number;
Min? : number;
Max? : number;
}
のようなルックスと呼ばれている
export class GridBuilder{
Settings : GridInit;
GridData : GridType[];
Grid : string = '';
constructor() {
this.Settings.GridStyle = 'SiteGridA';
this.GridData = GridDefs;
this.buildGrid(this.Settings, this.GridData);
}
buildGrid(core: GridInit, gridData: GridType[]) {
const w: number = multiply(core.Size.Width, core.Size.PixelRatio);
const h: number = multiply(core.Size.Height, core.Size.PixelRatio);
const o: string = checkOrientation(w, h);
const c: CellSpecs = calcCell(o, w);
const t: GridType = gridData.find(a => { a.GridName == core.GridStyle; return a; });
const cols: string = calcArea(t.Columns, c);
const rows: string = calcArea(t.Rows, c);
this.Grid = cols + '/' + rows;
}
}
GridType[]
は
- 設定されている達成しますパラメータ012グリッドに関するデータを取得するために、
.find()
メソッドで一致させる必要があります。 .find()
メソッドが検索する変数にグリッドデータを保存します。- 変数を関数に渡して、グリッドを作成します。
GridDefs
はかなりこの
export const GridDefs: GridType[] = [
{
GridName : 'SiteGridA',
Columns : [
{
Names : [ { Name: 'left-bleed-start' } ],
Type : 'normal',
CalcType : 'divide',
CSize : { Size: 4 }
},
{
Names : [ { Name: 'left-bleed-end'}, { Name: 'content-col-start' } ],
Type : 'normal',
CalcType : 'multiply',
CSize : { Size: 32.5 }
},
{
Names : [ { Name: 'content-col-end' }, { Name: 'right-bleed-start' } ],
Type : 'normal',
CalcType : 'divide',
CSize : { Size: 4 }
},
{
Names : [ { Name: 'right-bleed-end' } ],
Type : 'end',
CalcType : 'none',
CSize : { Size: null }
}
],
Rows : [
{
Names : [ { Name: 'top-bleed-start' } ],
Type : 'normal',
CalcType : 'divide',
CSize : { Size: 4 }
},
{
Names : [ { Name: 'top-bleed-end' }, { Name: 'link-row-start' } ],
Type : 'normal',
CalcType : 'multiply',
CSize : { Size: 2 }
},
{
Names : [ {Name: 'link-row-end'}, { Name: 'content-row-start' } ],
Type : 'normal',
CalcType : 'none',
CSize : { Size: 0 }
},
{
Names : [ { Name: 'content-row-end' }, { Name: 'footer-row-start' } ],
Type : 'normal',
CalcType : 'multiply',
CSize : { Size: 4}
},
{
Names : [ { Name: 'footer-row-end' }, { Name: 'bottom-bleed-start' } ],
Type : 'normal',
CalcType : 'divide',
CSize : { Size: 4 }
},
{
Names : [ { Name: 'bottom-bleed-end' } ],
Type : 'end',
CalcType : 'none',
CSize : { Size: null }
}
]
},
{
GridName : 'LinkContainerA',
Columns : [
{
Names : [ { Name: 'main-link-col-start' } ],
Type : 'normal',
CalcType : 'none',
CSize : { Size: 0 }
},
{
Names : [ { Name: 'main-link-col-end' }, { Name: 'feature-link-start' } ],
Type : 'normal',
CalcType : 'percent',
CSize : { Size: 50 }
},
{
Names : [ { Name: 'feature-link-end' } ],
Type : 'end',
CalcType : 'none',
CSize : { Size: null }
}
],
Rows : [
{
Names : [ { Name: 'content-row-sart' } ],
Type : 'normal',
CalcType : 'none',
CSize : { Size: 0 }
},
{
Names : [ { Name: 'content-row-end' } ],
Type : 'end',
CalcType : 'none',
CSize : { Size: null }
}
]
}
]
GridName
プロパティのように見える私はの線の内側にSettings
変数でGridStyle
パラメータと一致するようにしようとしています何であるグリッドの定義でありますエラーの原因となるコード
これまでのところ、OnInit
を追加して、コンストラクタが起動する前にグリッドデータをロードしているかどうか確認してみました。私は1と3を試みた=
符号をconst
let
のために切り替えてみました。私は本当にこれを超えて何をすべきかわかりません。私は同様の例で.find()
メソッドを使用しましたが、問題はありませんでした。これをどうすれば解決できますか?
検索:このように、
または中括弧、正しい返し(および正しく入力)return文で値を:あなたはこのように、
=>
後にカッコを囲むことなく、簡単な表現であることを行うことができますnull(要素が一致する場合)を返すことができます。だからあなたは "共用体の型"を使うことができます。これは "const t:GridType | null = ..."と書いてあります。 – Eliseo