我已经意识到可以使用普通函数创建小部件,而不是继承StatelessWidget的子类。一个例子是:

Widget function({ String title, VoidCallback callback }) {
  return GestureDetector(
    onTap: callback,
    child: // some widget
  );
}

这很有趣,因为它需要的代码比成熟的类要少得多。例子:

class SomeWidget extends StatelessWidget {
  final VoidCallback callback;
  final String title;

  const SomeWidget({Key key, this.callback, this.title}) : super(key: key);

  @override
  Widget build(BuildContext context) {
      return GestureDetector(
        onTap: callback,
        child: // some widget
      );
  }
}

所以我一直在想:在创建小部件时,除了语法之外,函数和类之间还有什么不同吗?使用函数是一种好的实践吗?

我想在Backbone.js模型中对表单进行一些服务器前验证。为此,我需要将用户输入的表单转换为可用的数据。 我找到了三种方法:

var input = $(“#inputId”).val(); var input = $(“form.login”).serialize(); var input = $(“form.login”).serializeArray();

不幸的是,没有一个提供我所需要的良好的可读和可开发的JSON对象。我已经浏览了Stack Overflow上的几个问题,但我只找到了一些额外的库。

现在的jQuery或Backbone.js没有提供一个辅助方法吗?

我无法想象没有对这种功能的要求。

HTML

<form class="login">
    <label for="_user_name">username:</label>
    <input type="text" id="_user_name" name="user[name]" value="dev.pus" />
    <label for="_user_pass">password:</label>
    <input type="password" id="_user_pass" name="user[pass]" value="1234" />
    <button type="submit">login</button>
</form>

JavaScript

var formData = $("form.login").serializeObject();
console.log(formData);

输出

{
    "name": "dev.pus",
    "pass": "1234"
}

Backbone.js模型

var user = new User(formData);
user.save();

如果你曾经使用过JavaScript,你就会知道Internet Explorer没有为Array.prototype.indexOf()[包括Internet Explorer 8]实现ECMAScript函数。这不是一个大问题,因为您可以使用以下代码扩展页面上的功能。

Array.prototype.indexOf = function(obj, start) {
     for (var i = (start || 0), j = this.length; i < j; i++) {
         if (this[i] === obj) { return i; }
     }
     return -1;
}

我应该什么时候实现这个?

我是否应该用下面的检查将它包装在我的所有页面上,检查原型函数是否存在,如果不存在,继续扩展数组原型?

if (!Array.prototype.indexOf) {

    // Implement function here

}

或者做浏览器检查,如果是ie,就实现它?

//Pseudo-code

if (browser == IE Style Browser) {

     // Implement function here

}

我想从一个c#程序执行这个存储过程。

我在SqlServer查询窗口中编写了以下存储过程,并将其保存为 stored1:

use master 
go
create procedure dbo.test as

DECLARE @command as varchar(1000), @i int
SET @i = 0
WHILE @i < 5
BEGIN
Print 'I VALUE ' +CONVERT(varchar(20),@i)
EXEC(@command)
SET @i = @i + 1
END

编辑:

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace AutomationApp
{
    class Program
    {
        public void RunStoredProc()
        {
            SqlConnection conn = null;
            SqlDataReader rdr  = null;

            Console.WriteLine("\nTop 10 Most Expensive Products:\n");

            try
            {
                conn = new SqlConnection("Server=(local);DataBase=master;Integrated Security=SSPI");
                conn.Open();
                SqlCommand cmd = new SqlCommand("dbo.test", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                rdr = cmd.ExecuteReader();
                /*while (rdr.Read())
                {
                    Console.WriteLine(
                        "Product: {0,-25} Price: ${1,6:####.00}",
                        rdr["TenMostExpensiveProducts"],
                        rdr["UnitPrice"]);
                }*/
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
                if (rdr != null)
                {
                    rdr.Close();
                }
            }
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World");
            Program p= new Program();
            p.RunStoredProc();      
            Console.Read();
        }
    }
}

这将显示异常无法找到存储过程dbo.test。我需要提供路径吗?如果是,存储过程应该存储在哪个位置?

我想移动一个表到一个特定的模式使用T-SQL?我使用的是SQL Server 2008。

JavaScript数组#sort()函数使用哪种算法?我知道它可以使用各种各样的参数和函数来执行不同的排序,我只是对普通排序使用哪种算法感兴趣。

如何检查应用程序是否从批处理(好cmd)文件运行?

如果程序已经在运行,我不需要启动另一个实例。(我不能改变应用程序,使它只有单一实例。)

此外,应用程序可以作为任何用户运行。

在windows机器上,我得到这个错误

“touch”不能被识别为内部或外部命令、可操作程序或批处理文件。

我遵循这些指令,似乎是linux特定的,但在标准的windows命令行上,它不是这样工作的:

touch index.html app.js style.css

windows中是否有类似于linux / mac os / unix世界中的'touch'命令?为了实现这类命令,我是否需要手工创建这些文件(并修改它们以更改时间戳)?我正在使用节点,这似乎不是很…node-ish……

我有一个功能正常的Rails 3应用程序,使用has_many:通过关联,这不是,因为我把它重新制作为Rails 4应用程序,让我保存id从相关的模型在Rails 4版本。

这是三个相关的模型是相同的两个版本。

Categorization.rb

class Categorization < ActiveRecord::Base

  belongs_to :question
  belongs_to :category
end

Question.rb

has_many :categorizations
has_many :categories, through: :categorizations

Category.rb

has_many :categorizations
has_many :questions, through: :categorizations

在两个应用中,类别id都像这样传递到创建动作中

  "question"=>{"question_content"=>"How do you spell car?", "question_details"=>"blah ", "category_ids"=>["", "2"],

在Rails 3应用程序中,当我创建一个新问题时,它会插入到问题表中,然后插入到分类表中

 SQL (82.1ms)  INSERT INTO "questions" ("accepted_answer_id", "city", "created_at", "details", "province", "province_id", "question", "updated_at", "user_id") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)  [["accepted_answer_id", nil], ["city", "dd"], ["created_at", Tue, 14 May 2013 17:10:25 UTC +00:00], ["details", "greyound?"], ["province", nil], ["province_id", 2], ["question", "Whos' the biggest dog in the world"], ["updated_at", Tue, 14 May 2013 17:10:25 UTC +00:00], ["user_id", 53]]
  SQL (0.4ms)  INSERT INTO "categorizations" ("category_id", "created_at", "question_id", "updated_at") VALUES (?, ?, ?, ?)  [["category_id", 2], ["created_at", Tue, 14 May 2013 17:10:25 UTC +00:00], ["question_id", 66], ["updated_at", Tue, 14 May 2013 17:10:25 UTC +00:00]]

在rails 4应用程序中,在它处理questioncontroller# create中的参数后,我在服务器日志中得到这个错误

Unpermitted parameters: category_ids

问题只是被插入到问题表中

 (0.2ms)  BEGIN
  SQL (67.6ms)  INSERT INTO "questions" ("city", "created_at", "province_id", "question_content", "question_details", "updated_at", "user_id") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id"  [["city", "dd"], ["created_at", Tue, 14 May 2013 17:17:53 UTC +00:00], ["province_id", 3], ["question_content", "How's your car?"], ["question_details", "is it runnign"], ["updated_at", Tue, 14 May 2013 17:17:53 UTC +00:00], ["user_id", 12]]
   (31.9ms)  COMMIT

虽然我没有在Questions模型中存储category_ids,但我将category_ids设置为questions_controller中的一个允许参数

   def question_params

      params.require(:question).permit(:question_details, :question_content, :user_id, :accepted_answer_id, :province_id, :city, :category_ids)
    end

有人能解释一下我应该如何保存category_ids吗?注意,在categorories_controller中没有创建动作。任意一个应用程序的Rb。

这三个表在两个应用中是一样的

 create_table "questions", force: true do |t|
    t.text     "question_details"
    t.string   "question_content"
    t.integer  "user_id"
    t.integer  "accepted_answer_id"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.integer  "province_id"
    t.string   "city"
  end

 create_table "categories", force: true do |t|
    t.string   "name"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

  create_table "categorizations", force: true do |t|
    t.integer  "category_id"
    t.integer  "question_id"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

更新

这是Rails 3应用程序的创建操作

  def create
      @question = Question.new(params[:question])
      respond_to do |format|
      if @question.save
        format.html { redirect_to @question, notice: 'Question was successfully created.' }
        format.json { render json: @question, status: :created, location: @question }
      else
        format.html { render action: "new" }
        format.json { render json: @question.errors, status: :unprocessable_entity }
      end
    end
end

这是Rails 4应用程序的创建操作

   def create
      @question = Question.new(question_params)

       respond_to do |format|
      if @question.save
        format.html { redirect_to @question, notice: 'Question was successfully created.' }
        format.json { render json: @question, status: :created, location: @question }
      else
        format.html { render action: "new" }
        format.json { render json: @question.errors, status: :unprocessable_entity }
      end
    end
    end

这是question_params方法

 private
    def question_params 
      params.require(:question).permit(:question_details, :question_content, :user_id, :accepted_answer_id, :province_id, :city, :category_ids)
    end