app.controller("restaurants", ["$scope", "$resource", function ($scope, $resource) {
var Restaurant = $resource('/api/restaurants/:id');
var clearForm = function () {
$scope.name = '';
$scope.address = '';
$scope.rating = null;
}
clearForm();
var validRestaurant = function () {
if($scope.name !== '' && $scope.address !== '' && $scope.rating !== null)
return true;
else{
toastr.error("Please fill in all required form fields.");
return false;
}
}
$scope.query = function(){
Restaurant.query(function (results) {
$scope.restaurants = results;
});
};
$scope.add = function () {
alert("got here!");
if(validRestaurant()){
var restaurant = new Restaurant();
restaurant.name = $scope.name;
restaurant.address = $scope.address;
restaurant.rating = $scope.rating;
alert(restaurant);
Restaurant.save(restaurant, function (result) {
$scope.restaurants.push(result);
toastr.success("Saved " + $scope.name + ".")
clearForm();
});
}
};
$scope.update = function (id) {
};
$scope.remove = function (id) {
console.log(id);
Restaurant.delete({id: id}, function (err) {
console.log(err);
$scope.query();
});
};
$scope.query();
}]);
和setText(CharSequence, TextView.BufferType)
之间的区别是什么?我们何时应该使用它们?
答案 0 :(得分:1)
您可以看到与textview代码的区别..
if (type == BufferType.EDITABLE || getKeyListener() != null ||
needEditableForNotification) {
createEditorIfNeeded();
Editable t = mEditableFactory.newEditable(text);
text = t;
setFilters(t, mFilters);
InputMethodManager imm = InputMethodManager.peekInstance();
if (imm != null) imm.restartInput(this);
} else if (type == BufferType.SPANNABLE || mMovement != null) {
text = mSpannableFactory.newSpannable(text);
} else if (!(text instanceof CharWrapper)) {
text = TextUtils.stringOrSpannedString(text);
}
如果你默认使用普通的setText,它采用TextView.BufferType.NORMAL的类型,它基本上是SpannedString的普通字符串。
答案 1 :(得分:0)
根据文档的不同之处在于,setText(CharSequence,TextView.BufferType)
还设置文本是否存储在可设置样式/可跨接的缓冲区中以及是否可编辑。
http://developer.android.com/reference/android/widget/TextView.html#setText(java.lang.CharSequence)
答案 2 :(得分:0)
setText (CharSequence text)
设置TextView的字符串值。而
setText (CharSequence text, TextView.BufferType type)
设置此TextView要显示的文本,并设置它是否存储在可设置样式/ spannable的缓冲区中以及是否可编辑。
所有BufferType选项均为:
例如
myEditText.setText("This is new text from setText with BufferType EDITABLE.", TextView.BufferType.EDITABLE);