Trying to use TaffyDB in an AngularJS project, but i'm unable to get Taffy working.
Every time i try to get data from the TaffyDB, it's empty:
Object {extend: undefined, insert: undefined}
I'm just tying to do a simple test from their website:
<script src="vendors/taffydb-master/taffy.js"></script>
<script>
$(document).ready(function () {
//TaffyDB
var friends = TAFFY([
{"id":1,"gender":"M","first":"John","last":"Smith","city":"Seattle, WA","status":"Active"},
{"id":2,"gender":"F","first":"Kelly","last":"Ruth","city":"Dallas, TX","status":"Active"},
{"id":3,"gender":"M","first":"Jeff","last":"Stevenson","city":"Washington, D.C.","status":"Active"},
{"id":4,"gender":"F","first":"Jennifer","last":"Gill","city":"Seattle, WA","status":"Active"}
]);
console.log(friends());
});
</script>
What am i doing wrong?
Change
console.log(friends());
instead do
console.log(friends().get());
Related
I have initialized firebase and want to write into database . I want unique code for every child but i am not able to do that i tried many things but i can't please help me to do this ..............
codes are below tell me where i am wrong
<script src="https://www.gstatic.com/firebasejs/4.1.3/firebase.js"></script>
<script>
var rootRef = firebase.database().ref().child('user');
$('#tex').click(function(){
rootRef.set({
emailinfo:$('#emailinfo').val()
});
});
</script>
You should use the push() method (which "generates a new child location using a unique key and returns its Reference"), as follows:
<script>
var rootRef = firebase.database().ref().child('user');
var newNodeRef = rootRef.push();
$('#tex').click(function(){
newNodeRef.set({
emailinfo:$('#emailinfo').val()
});
});
</script>
i started work with LINQ in javascript using http://jslinq.codeplex.com/ where it is suggested to add package jslinq. I added it and started with following query
var exampleArray = JSLINQ(myList)
.Where(function(item){ return item.FirstName == "Chris"; })
.OrderBy(function(item) { return item.FirstName; })
.Select(function(item){ return item.FirstName; });
but while debugging, on first line (var exampleArray = JSLINQ(myList)) shown error like 'uncought reference error JSLINQ not defined'..
please inform me what i am missing.. i am completely new to this.. thanks in advance.
Have You added
<SCRIPT type="text/javascript" src="/scripts/JSLinq.js"></SCRIPT>
before you call JSLINQ(myList) ?
Trying to utilize chart.js in my laravel app. In my controller, I'm using Eloquent to perform a simple query of the database:
//sampleController.php
public function test()
{
$inventories = Inventory::all();
$dates = $inventories->lists('updated_at');
$totals = $inventories->lists('item_4801');
return view('pages.test')
->with('dates')
->with('totals');
}
I'm passing 'dates' and 'totals' to my view:
//test.blade.php
#extends('app')
#section('content')
<canvas id="myChart" width="400" height="400"></canvas>
#stop
#section('footer')
<script src="assets/admin/js/Chart.min.js"></script>
<script>
var ctx = document.getElementById("myChart").getContext("2d");
var data = {
labels: {!! json_encode($dates) !!},
datasets: [
{
label: "My Data",
data: {!! json_encode($totals) !!}
}
]
};
var myLineChart = new Chart(ctx).Line(data);
</script>
#stop
This doesn't work. The chart placeholder shows but it seems the data is being read as null. I'm guessing I'm just not passing the data in the correct format, but not sure exactly how I would do that. I can confirm that the data is being passed from controller to view, as I can dump the variable and see the data. Evidently it's just not in a format that chartjs can understand.
Any information would be greatly appreciated. Just a nudge in the right direction would help.
Many thanks,
Clay
Turns out, it was the 'dates' variable causing the problem (in addition to a syntax error). Chartjs was looking for an array like:
["2015/06/08", 2015/06/13", "2015/6/20"]
instead of the collection object from the eloquent query.
So I ran $dates = array_column($inventories->toArray(), 'updated_at'); to get the array, then reformatted the dates by running:
foreach ($dates as $date){
$formatted_dates[] = date('m/d/Y', strtotime($date));
}
Then I passed $formatted_dates to the view.
I'm sure there's a better way, but I'm learning more everyday and it works for me!
In your model;
use this
public function getCreatedAtAttribute($value)
{
return date('m/d/Y', strtotime($value));
}
I'm trying to get the value of the first 'price' field at the url:
http://pubapi.cryptsy.com/api.php?method=singleorderdata&marketid=132
I am currently using the following code to do so:
getJSON('http://pubapi.cryptsy.com/api.php?
method=singleorderdata&marketid=132').then(function(data) {
var final = (data.return.DOGE.sellorders.price * totalcost) * 0.985
var finished = final.toFixed(8)
I have a strong feeling that I have done this bit wrong:
data.return.DOGE.sellorders.price
Any ideas?
Thanks!
data.return.DOGE.sellorders[0].price because sellorders is an array
$.getJSON('http://jsbin.com/pudoki/1.json', function(data){
alert(data.return.DOGE.sellorders[0].price);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
I have a list like this which I the server gives to the template:
test_data/reads_1.fq
test_data/reads_2.fq
test_data/test_ref.bt2
test_data/test_ref.ebwt
test_data/test_ref.fa
test_data/test_ref2.bt2
test_data/new_directory/ok.txt
I want to show these files in a tree view like this:
test_data
reads_1.fq
reads_1.fq
test_ref.bt2
test_ref.ebwt
test_ref.ebwt
new_directory
ok.txt
What's the best possible way to do like this? Thanks
Edit
I am sending my data like this as a list(Python):
['test_data/reads1.fq', 'test_data/reads_2.fq', test_data/new_directory/ok.txt]
Edit2
$(document).ready(function(){
var string=["test_data/new_directory/ok.txt","test_data/reads_1.fq","test_data/test_ref.fa"];
for(var i=0;i<string.length;i++){
var result = string[i].split('/');
$('html').html('<ul><li>'+result[0]+'</li><ul><li>'+result[1]+'</li><ul><li>'+result[2]+'</li></ul></ul>');
}
});
Result
test_data
test_ref.fa
undefined
Expected Result:
test_data
reads_1.fq
reads_2.fq
new_directory
ok.txt
Try this:
<script type="text/javascript">
$(document).ready(function(){
var string=["test_data/new_directory/ok.txt","test_data/reads_1.fq","test_data/test_ref.fa"];
for(var i=0;i<string.length;i++){
var result = string[i].split('/');
console.log(result);
}
});
</script>
it may not be the best practice, but you need something like this. You also may put your string into array to check whether indexes are the same to avoid the repetition. If I ave time I will look into this properly.