2014年11月

How to store only ID in dropdown Bootstrap

<div class="form-group">                           
<label for="title" class="col-sm-2 control-label">Section Id</label>
<div class="col-sm-10">
<select ng-model="product.sectionId" class="form-control" ng-options="section.name for section in sections track by section.id">
</select>
</div>
</div>


This is my code, I populate the sections object via JSON and section has id,name. I want to store only section.id in my product.sectionId but it stores both section id and name as below
"sectionId":{"id":"Iron Man","name":"Superman"}. I want only the id to be stored. Is there a way to do that. Im new to bootstrap and angularjs please help me. thank you



Answers

Change your ng-option to



Markup



ng-options="section.id as section.name for section in sections"


This will should section.name and select section.id when you select any of the option.



Direct From Docs




Do not use select as and track by in the same expression. They are not
designed to work together.





Can't install webkit-server

(PYTHON 2.7) I'm trying to install webkit-server. The problem is that it returns this error:



running install
running build
'make' is not recognized as an internal or external command,
operable program or batch file.
error: [Errno 2] No such file or directory: 'src/webkit_server'


Do you have any idea how to avoid this error? Or is there a msi or exe setup for webkit-server?





Question

I am on F-1 visa. There is a fellowship foundation (U.S.) willing to pay me to conduct research abroad. According to F-1 visa, I am not allowed to work off-campus without CPT or OPT but since the service is conducted abroad, I wonder whether I can receive this is payment or not. Note that, during the research period, my F-1 visa will be invalid because I will be taking a leave of absence from my school. Thanks a lot!



Answer

Please call me at (212) 968-8600 or toll-free at (800) 750-1828. Kind regards, RDM





How to get and append most recent messages from server using jQuery and AJAX?

I'm working on my first simple chat application and this issue has me stuck. I know what I'm trying to do, but I end up overthinking it.



Basically, I have this heroku server going:



http://tiy-fee-rest.herokuapp.com/collections/blabberTalk



Whenever someone sends a message, it is added to this array.



My Issue:



I have it on a set interval so that every 2 seconds, it runs the getNewestMessages function. When this setInterval is working and someone sends a message, it will keep appending the last message they sent every 2 seconds. If I disable the setInterval and simply call the getNewestMessages function myself in a separate browser tab, this doesn't seem to happen. I want to make it so that the most recently sent message isn't constantly re-appended to the DOM when the setInterval is active.



This is the function I'm using to check for recent messages. It's pretty bloated, sorry about that:



  getNewestMessages: function() {
$.ajax({
url: http://tiy-fee-rest.herokuapp.com/collections/blabberTalk,
method: 'GET',
success: function (data) {
// Finds Id of most recent message displayed in the DOM
var recentId = $('.message').last().data('id');
var prevMostRecent = 0;
var newMostRecent = [];
jQuery.each(data, function(idx,el){
if (el._id === recentId) {
// if one of the messages on the server has an Id equal to
// one of the messages in the DOM, it saves its index in a var
prevMostRecent = idx;
}
});
jQuery.each(data, function(idx,el){
if (idx < prevMostRecent) {
// if there are messages on the server with a lower index than
// the most recent message in the DOM, it pushes them to a new
// array. Basically, creates a new array of any messages newer
// than the last one displayed in the DOM.
newMostRecent.push(el);
}
});
for (var i = 0; i < newMostRecent.length; i++) {
console.log(newMostRecent[i]);
if (newMostRecent[i]._id === $('.message').last().data('id')) {
// My attempt at trying to remove the last DOM message from
// the array of newer messages. My main issue was that this
// whole function would keep appending the most recent message
// over and over again.
var result = _.without(newMostRecent, newMostRecent[i]);
console.log('MESSAGE TO BE EXCLUDED: ', newMostRecent[i]);
// If the array of newer messages contained the most recent
// DOM message, it removes it and sends it to be appended.
page.appendNewestMessages(result);
}
}
// If the array of newer messages DOESN'T contain the most recent
// DOM message, it just sends the whole array normally.
page.appendNewestMessages(newMostRecent);
},
error: function (err) {

}
});
}


Here is the append function:



appendNewestMessages: function(messagesToAppend) {
console.log(messagesToAppend.reverse());

_.each(messagesToAppend.reverse(), function(el, idx, arr) {
var newMessage = {
content: el.content,
timestamp: el.timestamp,
author: el.author,
userIcon: el.userIcon
}
$.ajax({
url: page.url,
method: 'POST',
data: newMessage,
success: function (data) {
page.addOneMessageToDOM(data);
},
error: function (err) {
console.log("error ", err);
}

});
})
}


Can anyone help me understand how to get the most recent messages from a server and append them to the DOM without any repeats? This has been driving me nuts.



Thanks for any and all help.





highcharts lines colors change but I don't want to

I'm using HighCharts to render two charts on a web page. I download the data for each charts dynamically with jquery and set the two charts with a setChart function.



function setChart(chart, name, data){
while (chart.series.length > 0) {
chart.series[0].remove(true);
}
for (var i = 0; i < data.length; i++) {
chart.addSeries({
name: name[i],
data: data[i],
});
}
}


The problem here is that when I download new datas with the jquery (= not refreshing the page), all the lines colors change.



How can I prevent HighCharts from changing the lines (=series) colors ?



Answers

You might want to create an array with colours you need. Lets call it colors. It has to have enough number of elements or else you will get out of bound error.



function setChart(chart, name, data){
while (chart.series.length > 0) {
chart.series[0].remove(true);
}
for (var i = 0; i < data.length; i++) {
chart.addSeries({
name: name[i],
data: data[i],
color: colors[i],
});
}
}


Answers

I mixed the two things in :



color: Highcharts.getOptions().colors[i % 10]


It work fine. The only thing that could be cool is it might be more than 10 colors, but I don't want to make them myself ^^



Thanks a lot ;)





↑このページのトップヘ