本文整理匯總了TypeScript中leancloud-storage.Object類的典型用法代碼示例。如果您正苦於以下問題:TypeScript Object類的具體用法?TypeScript Object怎麽用?TypeScript Object使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Object類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: before
before(function () {
// runs before all tests in this block
let todo: AV.Object = new AV.Object('Todo');// 新建對象
todo.set('location', '二樓大會議室');
return todo.save<AV.Object>().then(todo => {
todoObjectId = todo.id;
}, error => {
});
});
示例2: it
it('#AVObject#dataType', function (done) {
try {
let testNumber: number = 13;
let testString: string = 'here is a test string';
let testDate: Date = new Date('2016-06-04');
let testNumberArray: Array<number> = [1, 2, 3];
let testStringArray: Array<string> = ['here', 'is', 'a', 'string', 'array'];
let testObjectType: Object = { name: 'LeanCloud', url: 'https://leancloud.cn' };
let testAVObject = new AV.Object('TestClass');
testAVObject.set('testNumber', testNumber);
testAVObject.set('testString', testString);
testAVObject.set('testDate', testDate);
testAVObject.set('testNumberArray', testNumberArray);
testAVObject.set('testStringArray', testStringArray);
testAVObject.set('testObject', testObjectType);
testAVObject.save<AV.Object>().then(
(data) => {
chai.assert.isNotNull(data.id);
done();
}, (error) => {
if (error) throw error;
done();
});
}
catch (e) {
chai.assert.isNull(e);
}
});
示例3: it
it('AVObject#save', function (done) {
let todoFolder: AV.Object = new AV.Object('TodoFolder');// 新建對象
todoFolder.set('name', '工作');// 設置名稱
todoFolder.set('priority', 1);// 設置優先級
todoFolder.save<AV.Object>().then(
(data) => {
let savedTodoFolder: AV.Object = data;
chai.assert.isNotNull(savedTodoFolder, "new an AVObject with extend");
done();
}, (error) => {
if (error) throw error;
done();
});
});
示例4: before
before(function () {
// runs before all tests in this block
/*
AV.init({
appId:'{put-test-appId-here}}',
appKey:'{put-test-appKey-here}'});
*/
let todo: AV.Object = new AV.Object('Todo');// 新建對象
todo.set('title', '工程師周會');// 設置地點
todo.set('priority', 1);// 設置優先級
todo.set('location', '二樓會議室');// 設置地點
return todo.save<AV.Object>().then(todo=>{
testObjectId = todo.id;
},error=>{
});
});
示例5: test
test('test', (t) => {
t.plan(1);
let todo = new AV.Object('Todo');
todo.set('title', '工程師周會');
todo.set('content', '每周工程師會議,周一下午2點');
todo.save<AV.Object>().then(
(data) => {
// data 是根據 todo.save<AV.Object> 傳入的泛型參數決定
let savedTodo : AV.Object = data;
t.assert(savedTodo.id !== null, 'save todo object');
},
(error) => {
}
);
});
示例6: it
it('#new an AVObject with extend', function (done) {
try {
// 示例代碼-Start
var Todo = AV.Object.extend('Todo');
// 示例代碼-End
chai.assert.ok(Todo, "new an AVObject with extend");
done();
}
catch (e) {
chai.assert.isNull(e);
}
});
示例7: it
it('AVObject#setACL', function (done) {
try {
// 示例代碼-Start
// 新建一個帖子對象
let post = new AV.Object('Post');
post.set("title", "大家好,我是新人");
// 新建一個角色,並把為當前用戶賦予該角色
administratorRole = new AV.Role(randomRolename);//新建角色
let relation = administratorRole.getUsers();
administratorRole.getUsers().add(AV.User.current());//為當前用戶賦予該角色
administratorRole.save<AV.Role>().then(administratorRole => {//角色保存成功
// 新建一個 ACL 實例
let objectACL = new AV.ACL();
objectACL.setPublicReadAccess(true);
objectACL.setRoleWriteAccess(administratorRole, true);
// 將 ACL 實例賦予 Post 對象
post.setACL(objectACL);
post.save<AV.Object>().then(post => {
chai.assert.isNotNull(post.id);
done();
}, error => {
if (error) throw error;
});
}, error => {
//角色保存失敗,處理 error
});
// 示例代碼-End
}
catch (e) {
chai.assert.isNull(e);
}
});
示例8: it
it('AVObject#update', function (done) {
try {
// 示例代碼-Start
// 第一個參數是 className,第二個參數是 objectId
let todo: AV.Object = AV.Object.createWithoutData('Todo', todoObjectId);
// 修改屬性
todo.set('content', '每周工程師會議,本周改為周三下午3點半。');
// 保存到雲端
todo.save<AV.Object>().then(todo => {
chai.assert.isNotNull(todo.id);
done();
}, error => {
if (error) throw error;
});
// 示例代碼-End
}
catch (e) {
chai.assert.isNull(e);
}
});