[英]properties setting issue in javascript
當我將屬性作為名稱發送時,值的名稱將作為“名稱”發送,而不是名稱的參數值。 有解決辦法嗎? 現在,我使用案件以正確的方式發送。
/**
* Change properties of the elements
*/
this.changeProperties = function(type,value) {
switch(type)
{
case "stroke":
$.DrawEngine.changeProperties({"stroke":value});
break;
case "font-family":
$.DrawEngine.changeProperties({"font-family":value});
break;
}
};
this.changeProperties = function(type,value) {
$.DrawEngine.changeProperties({"stroke":value});
}
它發送{type:"red"}
而不是{"stroke": "red"}
您可能需要通過
this.changeProperties = function(type,value) {
var obj = {};
obj[type] = value;
$.DrawEngine.changeProperties(obj);
}
如果您試圖將對象添加為{type:value}
。 鍵不會被評估為類型的實際值,而是會變成鍵本身。 因此,您將需要使用數組符號插入要創建的類型的值作為鍵。
看到這個
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.