骨干为什么不发送删除?(why does backbone not send the delete?)
我有一个非常基本的骨干(样本)应用程序,只是创建和销毁模型项目。 创建模型时,对象会持续POST到Web服务器,但是当模型被销毁时,没有DELETE发送到服务器? 任何想法,为什么这可能是?
非常基本的模型:
window.User = Backbone.Model.extend({ urlRoot: 'users' });
我的测试代码只是为了创建和删除模型:
var model = null; $(".add").click(function(){ if (model == null) { model = new window.User; model.set({name: 'meeee'}); model.save(); } }); $(".remove").click(function(){ if (model != null) { model.destroy(); } });
创建模型时的JSON响应看起来也不错:
I have a very basic backbone (sample) application which just creates and destroys model items. When the model is created the object is persisted with a POST to the web server, but when the model is destroyed there is no DELETE sent to the server? Any idea why this might be?
very basic model:
window.User = Backbone.Model.extend({ urlRoot: 'users' });
my test code just to create and delete the model:
var model = null; $(".add").click(function(){ if (model == null) { model = new window.User; model.set({name: 'meeee'}); model.save(); } }); $(".remove").click(function(){ if (model != null) { model.destroy(); } });
The JSON response when creating the model seems good too:
原文:https://stackoverflow.com/questions/10874202
最满意答案
您可以使用:
string[] splitBySpace = line.Split(' '); string first = splitBySpace.ElementAt(0); decimal last = Convert.ToDecimal(splitBySpace.ElementAt(splitBySpace.Length - 1));
编辑:处理货币符号:
string[] splitBySpace = line.Split(' '); string pattern = @"[^0-9\.\,]+"; string first = splitBySpace.ElementAt(0); string last = (new Regex(pattern)).Split(splitBySpace.ElementAt(splitBySpace.Length - 1)) .FirstOrDefault(); decimal lastDecimal; bool success = decimal.TryParse(last, out lastDecimal);
You can use:
string[] splitBySpace = line.Split(' '); string first = splitBySpace.ElementAt(0); decimal last = Convert.ToDecimal(splitBySpace.ElementAt(splitBySpace.Length - 1));
Edit : To Handle Currency symbol:
string[] splitBySpace = line.Split(' '); string pattern = @"[^0-9\.\,]+"; string first = splitBySpace.ElementAt(0); string last = (new Regex(pattern)).Split(splitBySpace.ElementAt(splitBySpace.Length - 1)) .FirstOrDefault(); decimal lastDecimal; bool success = decimal.TryParse(last, out lastDecimal);
相关问答
更多-
TCP/IP模型是一个________。[2023-10-02]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
您可以使用open函数打开文件,然后按行迭代: with open("your_file.txt") as file: for line in file: do_something(line) 如果你想先存储这些IP地址(你可能应该这样做),你可以将它们包含在一个列表中( your_list = [] ),并用your_list.append(line)替换do_something(line) your_list.append(line) 。 请记住,您可能希望对每一行进行某 ...
-
您在循环的每次迭代中重复使用相同的列表m ,每次都会覆盖上一次迭代中设置的值。 最后, lis拥有许多对同一列表的引用。 相反,在循环中为m分配一个新值: for line in f: m = [0,0] m[0], m[1] = line.split(",") m[0] = int(m[0]) m[1] = int(m[1]) lis.append(m) 或更短: for line in f: m = line.split(",") m[0] ...
-
这是一个很好的方式我猜。 F = open('Data.gro', 'r') A = open('XYZ.txt', 'w') XO = [] YO = [] ZO = [] XHW1 = [] YHW1 = [] ZHW1 = [] XHW2 = [] YHW2 = [] ZHW2 = [] I = range(1, 10) with open('Data.gro') as F: for line in F: if line.split()[0] == '3000': ...
-
with open('data.txt') as f: polyShape = [] for line in f: line = line.split() # to deal with blank if line: # lines (ie skip them) line = [int(i) for i in line] polyShape.append(line) 会给你 [[0, 0, ...
-
您可以使用: string[] splitBySpace = line.Split(' '); string first = splitBySpace.ElementAt(0); decimal last = Convert.ToDecimal(splitBySpace.ElementAt(splitBySpace.Length - 1)); 编辑:处理货币符号: string[] splitBySpace = line.Split(' '); string pattern = @"[^0-9\.\,] ...
-
读取for line in f分割for line in f并且它在内存方面是有效的(它一次读取一行)但是将所有内容放在一个巨大的列表中则不然。 无论如何,如果你坚持: huge_list = [] with open(huge_file, "r") as f: for line in f: huge_list.extend(line.split()) 要将整个文件作为字符串读入内存,请使用f.read()代替: huge_list = [] with open(huge_fi ...
-
从文件中读取特定值并将它们存储在列表python中(read in specific values from a file and store them in a list python)[2023-04-29]
您可以尝试以下方法: with open(filename) as f: lines = [l.split() for l in f.readlines()] lines = [map(float, l[:3]) for l in lines if len(l)>=3] 这将仅使用> = 3列的行的三个第一列,并将所有值转换为float。 You can try the following: with open(filename) as f: lines = [l.split() for ... -
将特定列从text-file导入mysql ..这可能吗?(Import specific columns from text-file into mysql.. is this possible?)[2022-01-21]
您始终可以创建一个带有虚拟列的表,您可以在加载文件后删除它(假设您不必经常加载文件)。 像这样的东西: LOAD DATA LOCAL INFILE '/path/to/file' INTO TABLE table_name FIELDS TERMINATED BY '^' (dummy_column1, column1, dummy_column2, column2); ALTER TABLE table_name DROP dummy_column1; ALTER TABLE table_name DR ...