我有一个像这样的json对象
[{"SubLoc":"a","Description":"A","Equipment":""},{"SubLoc":"b","Description":"B","Equipment":""},{"SubLoc":"c","Description":"C","Equipment":""},{"SubLoc":"d","Description":"D","Equipment":""}]
我想在前面添加一个属性,以便JSON看起来像
[{"SubLoc":"Select","Description":"Select","Equipment":""},{"SubLoc":"a","Description":"A","Equipment":""},{"SubLoc":"b","Description":"B","Equipment":""},{"SubLoc":"c","Description":"C","Equipment":""},{"SubLoc":"d","Description":"D","Equipment":""}]
我试着像这样卸下 -
$scope.JsonVar.unshift({SubLoc:'Select', Description:'Select'});
但它给我这样的结果......
[{"SubLoc":"Select","Description":"Select","Equipment":""}[{"SubLoc":"a","Description":"A","Equipment":""},{"SubLoc":"b","Description":"B","Equipment":""},{"SubLoc":"c","Description":"C","Equipment":""},{"SubLoc":"d","Description":"D","Equipment":""}]]
答案 0 :(得分:1)
unshift()
方法返回数组的新长度,而不是数组本身。因此,您不得将结果重新分配给public function where_condition($column_name, $operator, $value, $reverse = false)
{
$multiple = is_array($column_name) ? $column_name : array($column_name => $value);
$result = $this;
foreach($multiple as $key => $val) {
// Add the table name in case of ambiguous columns
if (count($result->_join_sources) > 0 && strpos($key, '.') === false) {
$table = $result->_table_name;
if (!is_null($result->_table_alias)) {
$table = $result->_table_alias;
}
$key = "{$table}.{$key}";
}
$key = $result->_quote_identifier($key);
if($reverse)
$result = $result->_add_condition('where', "? {$operator} {$key}", $val);
else
$result = $result->_add_condition('where', "{$key} {$operator} ?", $val);
}
return $result;
}
。只需使用它:
$scope.JsonVar