我是javascript和stackmob的初学者。如何使用javascript从stackmob获取我的网页(仪表板)的数据?我也在尝试更新数据,但没有成功。
下面是我的代码,用于将'done‘的值从'false’更新为'true‘:
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" src="http://static.stackmob.com/js/stackmob-js-0.9.1-bundled-min.js"></script>
</head>
<body>
<script type="text/javascript">
StackMob.init({publicKey: "my_key",apiVersion: 0});
</script>
<script type="text/javascript">
var newtask = new task({ newtask_id: 'my_id_primarykey' });
newtask.save({done:true},{
success: function(model, result, options) {
console.debug(model.toJSON());}
error: function(model, result, options) {}});
</script>
<!-- rest of the code -->
</body>我需要能够创建一个实例(我已经能够做到),更新值,删除值和获取值。
我无法更新现有实例的多个值并将其保存到stackMob。
StackMob.init({publicKey:"mykey",apiVersion:0});
var Task=StackMob.Model.extend({schemaName:'taskdevice'});
var task1=new Task({task_device_id:'my_id'});
task1.save({imei:'112',name:document.getElementById('e2').value),dob:(document.getElementById('e3').value),email:(document.getElementById('e4').value),phone:(document.getElementById('e5').value)},{
success: function(model, result, options) {
alert("success");
console.debug(model.toJSON());},
error: function(model, error, options) {alert("Failure");}
});如果我尝试更新多个值,它每次都会失败。
发布于 2013-06-30 05:45:28
您的代码中有一些语法错误,例如成功回调和错误回调之间的逗号。此外,您还需要在尝试保存/读取数据之前定义您的模型。未定义您的task变量。因此,您可以扩展模型来定义它应该与什么schema相关。
下面是一个带工作示例的jsFiddle:http://jsfiddle.net/wyne/eATur/
你也可以在StackMob的开发者中心查看JavaScript Developer Guide。
// Initialize StackMob object with your public key
StackMob.init({
publicKey: "api_key", apiVersion: 0
});
// Define Model and associate it with a Schema
var Task = StackMob.Model.extend({ schemaName: 'task' });
$(document).ready(function () {
// Create new instance of the Model with id of object to update
var updateTask = new Task({ "task_id": "INSERT_OBJECT_ID" });
// Update the task with done=false and save it to StackMob
updateTask.save({ done: true }, {
success: function(model, result, options) {
console.log( "Updated object!" );
console.log( model.toJSON() );
},
error: function(model, error, options) {
console.log( "Error updating" );
}
});
});https://stackoverflow.com/questions/17384069
复制相似问题