添加元素到 results.items
Add element to results.items
我正在尝试将新属性添加到 item
例如,如果我创建以下查询
wixData.query("myCollection")
.find()
.then( (results) => {
if(results.items.length > 0) {
let items = results.items; // see below
} else {
// handle case where no matching items found
}
} ) ;
我会得到这个数组
/* items:
*
* [
* {
* "_id": "1234",
* "_owner": "f45jf8d2-grkj-2opd-4ovk-9rfj4wo5tvj3",
* "_createdDate": "2017-05-29T08:35:52.344Z",
* "_updatedDate": "2017-05-29T08:35:52.344Z",
* "title": "Dr.",
* "first_name": "Jane",
* "last_name": "Doe",
* "status": "active"
* },
* {
* "_id": "5678",
* "_owner": "f45jf8d2-grkj-2opd-4ovk-9rfj4wo5tvj3",
* "_createdDate": "2017-05-25T12:48:56.572Z",
* "_updatedDate": "2017-05-29T07:30:15.869Z",
* "title": "Mr.",
* "first_name": "John",
* "last_name": "Doe",
* "status": "active"
* }
* ]
*/
但是如何添加另一个键,例如
"image": "http://image.com"
我试过了
results.items[0].add("image","http://image.com")
但是没用
刚刚
items[0].image = 'http://image.com';
或
items[0] = {...items[0], image: 'http://image.com'};
我正在尝试将新属性添加到 item
例如,如果我创建以下查询
wixData.query("myCollection")
.find()
.then( (results) => {
if(results.items.length > 0) {
let items = results.items; // see below
} else {
// handle case where no matching items found
}
} ) ;
我会得到这个数组
/* items:
*
* [
* {
* "_id": "1234",
* "_owner": "f45jf8d2-grkj-2opd-4ovk-9rfj4wo5tvj3",
* "_createdDate": "2017-05-29T08:35:52.344Z",
* "_updatedDate": "2017-05-29T08:35:52.344Z",
* "title": "Dr.",
* "first_name": "Jane",
* "last_name": "Doe",
* "status": "active"
* },
* {
* "_id": "5678",
* "_owner": "f45jf8d2-grkj-2opd-4ovk-9rfj4wo5tvj3",
* "_createdDate": "2017-05-25T12:48:56.572Z",
* "_updatedDate": "2017-05-29T07:30:15.869Z",
* "title": "Mr.",
* "first_name": "John",
* "last_name": "Doe",
* "status": "active"
* }
* ]
*/
但是如何添加另一个键,例如
"image": "http://image.com"
我试过了
results.items[0].add("image","http://image.com")
但是没用
刚刚
items[0].image = 'http://image.com';
或
items[0] = {...items[0], image: 'http://image.com'};