Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SAPUI5-属性范围_Sapui5 - Fatal编程技术网

SAPUI5-属性范围

SAPUI5-属性范围,sapui5,Sapui5,我有两个控件,一个从控件扩展,另一个从自定义控件扩展 控件有一个数组属性,我希望每个实例都是唯一的: /* parent control */ sap.ui.core.Control.extend("foo.MyControl", { metadata: { properties: { name: { type: 'string' }, myArray: { type: 'array', defaultValue: [] }

我有两个控件,一个从控件扩展,另一个从自定义控件扩展

控件有一个数组属性,我希望每个实例都是唯一的:

/* parent control */
sap.ui.core.Control.extend("foo.MyControl", {
    metadata: {
        properties: {
            name: { type: 'string' },
            myArray: { type: 'array', defaultValue: [] }
        }
    },
    renderer: {
        render: function( oRenderManager, oControl ) {
            oRenderManager.write('<div>My name is: ' + oControl.getName() + '</div>');
        }
    }
});

/* child control */
foo.MyControl.extend("foo.MyChildControl", {
    renderer: {
        render: foo.MyControl.prototype.render
    }
});
为什么这两个数组实例相等

alert(oMyControl.getMyArray() === oMyChildControl.getMyArray()); // true
我希望每个实例都有自己的数组

**

TL;DR用于定义控件元数据,将数组属性声明为类型“object”
**我在尝试运行代码时遇到异常

类型:“数组”不正确

JavaScript中的typeof运算符为数组返回“object”

这对我有用

sap.ui.core.Control.extend("foo.MyControl", {
    metadata: {
        properties: {
            name: {
                type: 'string'
            },
            myArray: {
                type: 'object',
                defaultValue: []
            }
        }
    },
    renderer: {
        render: function(oRenderManager, oControl) {
            oRenderManager.write('<div>' + oControl.getMyArray().toString() + '</div>');
        }
    }
});

/* child control */
foo.MyControl.extend("foo.MyChildControl", {
    renderer: {
        render: foo.MyControl.prototype.render
    }
});

/* create and place instances */
var oMyControl = new foo.MyControl({
    name: 'parent control'
}).placeAt('content');

var oMyChildControl = new foo.MyChildControl({
        name: 'child control'
}).placeAt('content');

var aFruits = ["Banana", "Orange", "Apple", "Mango"];
var aColors = ["Red", "Blue", "Green"];
oMyControl.setMyArray(aFruits);
oMyChildControl.setMyArray(aColors);
sap.ui.core.Control.extend(“foo.MyControl”{
元数据:{
特性:{
姓名:{
键入:“字符串”
},
myArray:{
类型:“对象”,
默认值:[]
}
}
},
渲染器:{
渲染:函数(oRenderManager、oControl){
写入(“”+oControl.getMyArray().toString()+“”);
}
}
});
/*子控件*/
foo.MyControl.extend(“foo.MyChildControl”{
渲染器:{
render:foo.MyControl.prototype.render
}
});
/*创建并放置实例*/
var MyControl=new foo.MyControl({
名称:“父控件”
}).placeAt(“内容”);
var MyChildControl=new foo.MyChildControl({
名称:“子控件”
}).placeAt(“内容”);
var aFruits=[“香蕉”、“橘子”、“苹果”、“芒果”];
var aColors=[“红色”、“蓝色”、“绿色”];
oMyControl.setMyArray(aFruits);
mychildcontrol.setMyArray(aColors);

您的示例中可能缺少代码,因为它的内容为:omicontrol.getMyArray()==[]&&omichildControl.getMyArray()===[],([]===[])true如果我填充omicontrol.getMyArray(),它也会填充omichildControl.getMyArray(),因为它们共享同一个引用,这正是我所困惑的。我希望他们有自己的数组实例。
sap.ui.core.Control.extend("foo.MyControl", {
    metadata: {
        properties: {
            name: {
                type: 'string'
            },
            myArray: {
                type: 'object',
                defaultValue: []
            }
        }
    },
    renderer: {
        render: function(oRenderManager, oControl) {
            oRenderManager.write('<div>' + oControl.getMyArray().toString() + '</div>');
        }
    }
});

/* child control */
foo.MyControl.extend("foo.MyChildControl", {
    renderer: {
        render: foo.MyControl.prototype.render
    }
});

/* create and place instances */
var oMyControl = new foo.MyControl({
    name: 'parent control'
}).placeAt('content');

var oMyChildControl = new foo.MyChildControl({
        name: 'child control'
}).placeAt('content');

var aFruits = ["Banana", "Orange", "Apple", "Mango"];
var aColors = ["Red", "Blue", "Green"];
oMyControl.setMyArray(aFruits);
oMyChildControl.setMyArray(aColors);