小编Atm*_*tma的帖子

如何将JSON解析为HighCharts线图?

我试图远程解析以下JSON字符串:

[{"name":"Object1","data":[1,2]},{"name":"Object2","data":[3,4]}]
Run Code Online (Sandbox Code Playgroud)

我这样做是用以下代码:

$(function () {
  var chart;
  $(document).ready(function() {
    var options = {
      chart: {
        renderTo: 'container',
        type: 'line',
        marginRight: 130,
        marginBottom: 25
      },
      title: {
        text: 'hits by time',
        x: -20 //center
      },
      subtitle: {
        text: 'Source:',
        x: -20
      },
      xAxis: {
        categories: ['8am', '9am', '10am', '11am', '12pm', '1pm',
        '2pm', '3pm', '4pm', '5pm', '6pm', '7pm']
      },
      yAxis: {
        title: {
          text: 'Hits'
        },
        plotLines: [{
          value: 0,
          width: 1,
          color: '#808080'
        }]
      },
      tooltip: {
        formatter: function() { …
Run Code Online (Sandbox Code Playgroud)

javascript jquery json highcharts

2
推荐指数
1
解决办法
1万
查看次数

删除Java ArrayList中的重复对象会导致并发修改错误

可能重复:
并发修改异常:添加到ArrayList

我正在尝试使用此方法从arraylist中删除重复值:

 public void hasDuplicates(List<Artifact> p_cars) {
    final List<String> usedNames = new ArrayList<String>();
    for (Artifact car : p_cars) {
        final String name = car.getObjectId();

        if (usedNames.contains(name)) {
            p_cars.remove(car);

        }

        usedNames.add(name);
    }

}
Run Code Online (Sandbox Code Playgroud)

如何在不同时修改arraylist的情况下删除这些重复值?

我在一个arraylist上这样做,如果这有助于上下文,则填充listview.

谢谢!

java android listview arraylist

2
推荐指数
1
解决办法
3271
查看次数

jstl if else选择/何时不评估变量

当我满足选择/何时条件时,我正在尝试打印一些html:

 <c:choose>
      <c:when test="${notification.placeId} == ${place.placeId}">
    ${notification.name}
  </c:when>
<c:otherwise>
    placeId: ${place.placeId} - notplaceid: ${notification.placeId}
    </c:otherwise>
 </c:choose>
Run Code Online (Sandbox Code Playgroud)

打印:placeId:50 - notplaceid:43 placeId:50 - notplaceid:47 placeId:50 - notplaceid:49 placeId:50 - notplaceid:50 placeId:50 - notplaceid:51 placeId:50 - notplaceid:51 placeId:50 - notplaceid :51 placeId:50 - notplaceid:51 placeId:50 - notplaceid:52 placeId:50 - notplaceid:53 placeId:50 - notplaceid:0 placeId:50 - notplaceid:0

这一切都打印出来,否则永远不会从when语句中打印通知名称.从打印中可以看出,粗体输出明显符合when条件,应打印通知名称.

有谁知道发生了什么?

jsp jstl el

2
推荐指数
1
解决办法
331
查看次数

多选字段不显示django中的queryset

我正在尝试创建一个由查询集填充的多选字段.

我的表单看起来像这样:

class GroupLocationForm(forms.Form):
    groups_field = forms.MultipleChoiceField(required=False, 
                                    widget=forms.CheckboxSelectMultiple)

    def __init__(self, customer_id, group_id):
        super(GroupLocationForm, self).__init__()
        customer = Customer.objects.get(pk=customer_id)

        self.fields['groups_field'].queryset = Group.objects.filter(location__customer = customer).distinct()
Run Code Online (Sandbox Code Playgroud)

我的表单中的选择没有任何表现.如果我添加:

MY_CHOICES = (
                  (1,'choice 1'),
)

groups_field = forms.MultipleChoiceField(required=False, 
                                    widget=forms.CheckboxSelectMultiple, choices=MY_CHOICES)
Run Code Online (Sandbox Code Playgroud)

选择显示没有任何问题.

为什么我的查询集没有分配给窗口小部件?

django django-forms

2
推荐指数
1
解决办法
3483
查看次数

插入排序不正确排序数组

这是我的插入排序,与"算法简介"一书中的方式完全相同:

def insertion_sort():
    A = [5,2,4,6,1,3]
    for j in range(1, len(A)):
        print 'j:'+str(j)
        key = A[j]
        print 'key:'+str(key)
        i=j-1
        print 'i:'+str(i)
        while i > 0 and A[i] > key:
            A[i+1] = A[i]
            i=i-1
            print 'new i: '+str(i)
        print 'swapping value: '+str(A[i]) + ' with value: '+str(A[i+1])
        print ' '
        A[i+1] = key
    print A
Run Code Online (Sandbox Code Playgroud)

这打印:

[5, 1, 2, 3, 4, 6]
Run Code Online (Sandbox Code Playgroud)

如果让它们失灵,我做错了什么?

python algorithm insertion-sort insertion-order

2
推荐指数
1
解决办法
57
查看次数

如何快速将自定义uitableviewcell用于情节提要

我正在使用情节提要创建一个自定义单元格。我已将此单元格连接到情节提要中的表视图:

import UIKit

class NewsCell: UITableViewCell {

    @IBOutlet weak var titleLabel: UILabel!
    @IBOutlet weak var summaryLabel: UILabel!



    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
Run Code Online (Sandbox Code Playgroud)

我的cellforrowatindexpath和init函数如下所示:

var newsItems:[NewsItem]

required init(coder aDecoder:NSCoder){
    newsItems = [NewsItem]()

    let item1 = NewsItem()
    item1.title = "I am so awesome"
    item1.summary = "My awesome summary."

    newsItems.append(item1)

    super.init(coder: aDecoder)
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: …
Run Code Online (Sandbox Code Playgroud)

iphone uitableview ios swift

2
推荐指数
1
解决办法
4598
查看次数

Python PIL Crop 不裁剪图像

我有以下函数来裁剪图像:

def crop(original_image):


    original_image = Image.open(original_image)
    original_image.crop((25, 25, 50, 50))
    #original_image.load()

    thumb_io = StringIO.StringIO()
    original_image.save(thumb_io, format='JPEG')

    thumb_file = InMemoryUploadedFile(thumb_io, None, 'foo2.jpg', 'image/jpeg',
                                  thumb_io.len, None)


    return thumb_file
Run Code Online (Sandbox Code Playgroud)

保存的图像只是原始图像,没有任何尺寸编辑。我尝试了负载和不负载,但这没有什么区别。

原始图像为 300 x 450。

我做错了什么,图像没有通过任何裁剪编辑保存?

python django image python-imaging-library python-2.7

2
推荐指数
1
解决办法
642
查看次数

如何在django管理表单save_model中获取字段值

我有以下型号:

class Guest(models.Model):
    first_name = models.CharField(max_length=128)
    last_name = models.CharField(max_length=128)
    category = models.ForeignKey(Category)
    player_achievement = models.ForeignKey(PlayerAchievement, related_name="guest_achievements")
    player = models.ForeignKey(Player)
Run Code Online (Sandbox Code Playgroud)

我希望在表单中选择要在我的save_model方法中使用的播放器:

def save_model(self, request, obj, form, change):
        player = ??? how do i get this from the admin form?


        obj.player = player
        obj.save()
Run Code Online (Sandbox Code Playgroud)

python django django-models django-forms django-admin

2
推荐指数
1
解决办法
2958
查看次数

如何将csv文件导入mysql表并自动递增

我正在尝试使用以下命令将 csv 文件导入 mysql:

mysqlimport --columns=name,amount,desc --ignore-lines=1 --fields-terminated-by=, --verbose --local -u muser -p mydb file.csv
Run Code Online (Sandbox Code Playgroud)

该文件包含字段但不包含主键。它看起来像这样:

name, amount, desc
Run Code Online (Sandbox Code Playgroud)

我的 mysql 表如下所示:

CREATE TABLE `organization` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(128) DEFAULT NULL,
  `amount` varchar(128) DEFAULT NULL,
  `desc` varchar(128) DEFAULT NULL,
Run Code Online (Sandbox Code Playgroud)

如何使用mysqlimport以导入 csv 文件并生成自动递增的 ID?

当我运行它时,我收到以下错误:

mysqlimport:错误:1467,无法从存储引擎读取自动增量值,当使用表:组织时

mysql csv mysqlimport

2
推荐指数
2
解决办法
7827
查看次数

如何从django中的manage.py调用不同的设置

我正在尝试在 django 中调用环境特定设置。

我发现你可以根据以下内容在 django admin 中执行一些关闭操作:https ://docs.djangoproject.com/en/2.0/topics/settings/#the-django-admin-utility

我用manage.py尝试过:

python3 manage.py runserver --settings=mysite.settings.prod_settings
Run Code Online (Sandbox Code Playgroud)

我收到错误:

ModuleNotFoundError:没有名为“mysite.settings.prod_settings”的模块;“mysite.settings”不是一个包

如何调用环境特定设置?

谢谢

python django django-manage.py django-settings

2
推荐指数
1
解决办法
3265
查看次数