2017-04-05 24 views
2

我想吉斯字段必須用型功能錯誤指定 - 梯形校正

  1. 實現我有什麼labConfigs表看起來像下面。對於LabConfigs表的每個項目,我想在域表中存儲「UserauthLevel」。

    所以這就是我想在域表中創建「布爾對象數組」。 以下是代碼相同。

    ****************LabConfigs*********************** 
        var LabConfigs = new keystone.List('LabConfigs'); 
    
        LabConfigs.add({ 
        configName: {type: Types.Text, required: true, initial: true, index: true}, 
        description: {type: Types.Text, required: true, initial: true, index: true}, 
        image: {type: Types.Text, required: true, initial: true, index: true}, 
        type: {type: Types.Text, required: true, initial: true, index: true}, 
        version: {type: Types.Text, required: true, initial: true, index: true}, 
        }); 
        ************************************************ 
    

    下面是我的域名錶的代碼: -

    **************************Domain table****** 
    
        var Domain = new keystone.List('Domain'); 
        Domain.add({ 
         domainName: {type: Types.Text, required: true, initial: true, index: true}, 
        labConfigs :{type: Types.Relationship, ref: 'LabConfigs',required: false,many: true}, 
        userauthlevel:[{ type: Types.Boolean}] 
        }); 
        Domain.defaultColumns = 'domainName'; 
        Domain.register(); 
    

    但在運行此拋出後,給我的錯誤: -

    throw new Error('Fields must be specified with a type function'); 
        ^
    

    爲了解決這個問題,我試着在下面的代碼域表

    Domain.schema.add ({ 
          userauthlevel : 
             [{ 
             type: Types.Text 
            }] 
         }); 
    

    但這也沒有幫助。

    任何建議如何解決這個問題,我知道它可能工作在貓鼬。

回答

1

您錯誤地爲您的userauthlevel屬性指定了布爾值數組。 Keystone沒有布爾數組類型,但它有Types.TextArray,您可以使用它來在文檔上存儲多個可能的布爾值。

userauthlevel: { types: Types.TextArray } 

您傳遞給它的任何數組被認爲是一個字符串數組,所以你必須任何存儲的值轉換爲對自己的正確的真/假值。

+0

嗨,因爲我看不到任何TextArray的例子。你能指出我正確的例子TextArray。 –

+0

[這裏是](https://github.com/keystonejs/keystone/tree/master/fields/types/textarray)從他們的GitHub回購一些文件。 –

+0

任何一個很好的例子,如何在這個TextArray的userauthlevel中插入元素 –

相關問題