嗨,我是React的新手。 我正在开发任务,我需要声明一个具有空值的数组:
this.state = {
position: [null,null,null,null,null,null,null,null]
};
此后,我为该数组分配了一些值,但是我的应用程序确实要求每个池只能更改一次。 问候
答案 0 :(得分:1)
如果将任务更改为 admin_routes:
host: "admin.{domain}"
resource: "@AppBundle/Controller/Admin"
type: annotation
requirements:
domain: domain.local|domain2.local
defaults: { domain: domain.local }
user_routes:
host: "user.{domain}"
resource: "@AppBundle/Controller/User"
type: annotation
requirements:
domain: domain3.local|domain4.local
defaults: { domain: domain3.local }
,只能将其从position
更改为另一个值,而不能再次更改为null
,则此操作很容易>
null
答案 1 :(得分:0)
您可以为此使用Proxy
let arr = Array(5).fill(null);
const validator = {
set:function(obj,prop,value){
if(obj[prop] !== null) throw "You can't change it again"
else obj[prop] = value;
}
}
var p = new Proxy(arr, validator);
p[1] = 2; //the element is successfully changed
console.log(JSON.stringify(p))
p[1] = 3; // changing again throw error.