這是我的代碼
var treedata = ['{ "id" : "ajson1", "parent" : "#", "text" : "Customer" }',
'{ "id" : "ajson2", "parent" : "ajson1", "text" : "Order number" }',
'{ "id" : "ajson3", "parent" : "ajson1", "text" : "Date" }',
'{ "id" : "ajson4", "parent" : "#", "text" : "Company Name" }',
'{ "id" : "ajson5", "parent" : "#", "text" : "Contact Name" }',
'{ "id" : "ajson6", "parent" : "#", "text" : "Name1" }',
'{ "id" : "ajson7", "parent" : "#", "text" : "Product number1" }'];
$('#data').jstree({
'core' : {
'data' : treedata
}
});
但是當我運行它時它什么也不做,但我們使用它
$('#data').jstree({
'core' : {
'data' : {
['{ "id" : "ajson1", "parent" : "#", "text" : "Customer" }',
'{ "id" : "ajson2", "parent" : "ajson1", "text" : "Order number" }',
'{ "id" : "ajson3", "parent" : "ajson1", "text" : "Date" }',
'{ "id" : "ajson4", "parent" : "#", "text" : "Company Name" }',
'{ "id" : "ajson5", "parent" : "#", "text" : "Contact Name" }',
'{ "id" : "ajson6", "parent" : "#", "text" : "Name1" }',
'{ "id" : "ajson7", "parent" : "#", "text" : "Product number1" }'];
}
}
});
它有效,所以我如何在資料中使用變數?
我想運行第一個代碼但它不起作用
uj5u.com熱心網友回復:
您的意思是要為屬性值使用變數嗎?
如果您只想使用變數:
let n = 42;
const obj = {
'id': n
}
如果你想把變數放在一個字串中,以下任何一種方法都有效:
let name = 'Bob';
const obj = {
'description1': `User, ${name}, is cool`,
'description2': 'User, ' name ', is cool',
'description3': 'User, '.concat(name, ', is cool')
};
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/360080.html
標籤:javascript
上一篇:定位資料屬性&運行功能問題
