我正在尝试运行一个随机函数,但还没有完全弄明白:
<script>
function randomFrom(array) {return array[Math.floor(Math.random() * array.length)];}
function randomchords(){randomFrom(['poop()', 'poop2()', 'poop3()']);}
function poop() { $(function() {ionian_c_vi() }); }
function poop2() { $(function() {ionian_c_iii() }), $(function() {ionian_c_iv() }); }
function poop3() { $(function() {ionian_c_vi() }), $(function() {ionian_c_i() }), $(function() {ionian_c_ii() }); }
</script>
Run Code Online (Sandbox Code Playgroud)
然后:
<button onclick="randomchords()" >Get some random chords</button>
Run Code Online (Sandbox Code Playgroud)
我是在正确的轨道上吗?
我只需要在DOM中使用textarea的html标记来反映用户输入的值.(编辑:用户输入内容,当您点击"检查元素"时它会显示出来)
一个令人满意的div工作得很好,但现在看来我毕竟需要一个textarea.有人知道用javascript或html5做这个的方法吗?
我正在尝试将其保存到Cloudant数据库:
[
{
"_id": "document_one",
"heynow": [
{
"Name": "one",
"Duration": 2,
"DurationUnit": "Hours"
},
{
"Name": "two",
"Duration": 40,
"DurationUnit": "Minutes"
}
]
},
{
"_id": "document_two",
"heynow": [
{
"Name": "three",
"Duration": 2,
"DurationUnit": "Hours"
},
{
"Name": "four",
"Duration": 40,
"DurationUnit": "Minutes"
}
]
}
]
Run Code Online (Sandbox Code Playgroud)
但显然它不喜欢外括号,因为它告诉我:
"error":"bad_request","reason":"Document must be a JSON object"
Run Code Online (Sandbox Code Playgroud)
JSONLint说这是有效的,所以我想我问是否有人知道如何格式化它以便可以输入Couchdb,因为外括号似乎导致问题.
这有效:
return articles.find({}, {sort: {'published': -1}, limit: 1});
Run Code Online (Sandbox Code Playgroud)
这不是:
sort_order = 'published';
return articles.find({}, {sort: {sort_order: -1}, limit: 1});
Run Code Online (Sandbox Code Playgroud)
有办法做到这一点吗?
对不起这个长度,但它让我有点疯狂:
假设我想在加载时获得项目的"标题"和".priority"键值.
首先让我们看看每件事的布局:
$scope.items = $firebase(new Firebase("https://****.firebaseio.com"));
$scope.items.$on('loaded', function() {
console.log($scope.items);
});
Run Code Online (Sandbox Code Playgroud)
有了这个,我们得到:
> Object {$bind: function, $add: function, $save: function, $set: function, $remove: function…}
> $add: function (item, cb) {
> $bind: function (scope, name) {
> $child: function (key) {
> $getIndex: function () {
> $on: function (type, callback) {
> $remove: function (key) {
> $save: function (key) {
> $set: function (newValue) {
> this is my item: Object
$$hashKey: "012"
$id: "this is my …Run Code Online (Sandbox Code Playgroud) javascript ×2
jquery ×2
angularfire ×1
cloudant ×1
couchdb ×1
firebase ×1
html5 ×1
json ×1
meteor ×1
mongodb ×1